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

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.

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........

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.