944,187 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5375
  • C++ RSS
Dec 28th, 2005
0

#include custom files

Expand Post »
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:

Quote ...
#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
Similar Threads
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Dec 28th, 2005
0

Re: #include custom files

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
C++ Syntax (Toggle Plain Text)
  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
C++ Syntax (Toggle Plain Text)
  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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005
Dec 28th, 2005
0

Re: #include custom files

ok then this aint working right...at the moment i have...

in main.cpp

C++ Syntax (Toggle Plain Text)
  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

C++ Syntax (Toggle Plain Text)
  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........
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004
Dec 28th, 2005
0

Re: #include custom files

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?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Dec 28th, 2005
0

Re: #include custom files

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
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: connectivity in Borland C
Next Thread in C++ Forum Timeline: CreateThread & CreateRemoteThread





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC