#include custom files

Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

#include custom files

 
0
  #1
Dec 28th, 2005
Hello, in 'cpp' code if I wish to include a header file its .H...ie

//function definitions are located in function.h . The implementation is loaded in functions.cpp, however some of the functions take parameters created in main. Therefore rather than including the following:

#include <iostream>
...
function.h
function.cpp
...
int main()...
that works but isnt the corect / best way is it? But when I create a link in the .h to the .cpp and vice versa it errors...any ideas?

Is the quote way the only way to fix it?

Cheers
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,161
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1437
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: #include custom files

 
0
  #2
Dec 28th, 2005
never never include *.cpp files inside othere *.cpp files. The *.cpp files should be compiled separately and both linked together. The header.h file should be included in both *.cpp files
  1. // header.cpp
  2. //
  3. // system includes
  4. #include <iostream>
  5. // local includes
  6. #include "header.h"
  7.  
  8. // header implmentation code
  9. //
  10. // blaba
  1. // main.cpp
  2. // header.cpp
  3. //
  4. // system includes
  5. #include <iostream>
  6. // local includes
  7. #include "header.h"
  8.  
  9. int main()
  10. {
  11. // blabla
  12. }


now depending on the compiler you should have a project that includes both *.cpp files and links them both along with other system libraries to produce the final executable program.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: #include custom files

 
0
  #3
Dec 28th, 2005
ok then this aint working right...at the moment i have...

in main.cpp

  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. #include functions.cpp
  6. #include funct.h

the reason I've done it because its compiles... if I did this:

main.cpp

  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. #include funct.h
  6.  
  7. -----
  8.  
  9. funct.h
  10.  
  11. #include functions.cpp
  12.  
  13. -------
and try and compile that I get over 73 error messages since some varibles that main create are used in the functions........
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,319
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 230
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: #include custom files

 
0
  #4
Dec 28th, 2005
I thought we went through this already.
http://www.daniweb.com/techtalkforums/post106155-6.html
http://www.daniweb.com/techtalkforum...169#post106169
Is this something new and different?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: #include custom files

 
0
  #5
Dec 28th, 2005
DUH!! taking a break and comming back helps! I had 2 .H files that both needed including in the .cpp file! Thanks lads for your help, most appricated
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC