DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   #include custom files (http://www.daniweb.com/forums/thread37223.html)

Acidburn Dec 28th, 2005 9:15 am
#include custom files
 
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

Ancient Dragon Dec 28th, 2005 10:15 am
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
// header.cpp
//
// system includes
#include <iostream>
// local includes
#include "header.h"

// header implmentation code
//
// blaba
// main.cpp
// header.cpp
//
// system includes
#include <iostream>
// local includes
#include "header.h"

int main()
{
  // blabla
}


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.

Acidburn Dec 28th, 2005 10:44 am
Re: #include custom files
 
ok then this aint working right...at the moment i have...

in main.cpp


#include <iostream>
using namespace std;

#include functions.cpp
#include funct.h

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

main.cpp


#include <iostream>
using namespace std;

#include funct.h

-----

funct.h

#include functions.cpp

-------
and try and compile that I get over 73 error messages since some varibles that main create are used in the functions........

Dave Sinkula Dec 28th, 2005 10:49 am
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?

Acidburn Dec 28th, 2005 12:26 pm
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 :D


All times are GMT -4. The time now is 10:30 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC