Question Authors' Forum

C++ program question with user defined header files

Re: C++ program question with user defined header files

by Richard Lobb -
Number of replies: 0
The normal pattern for C and C++ projects is that the main program #includes the .h files but not the .cpp files. The latter then need to be compiled separately and all then get linked to an executable by 'ld' (usually invoked by the compiler itself). A single command like "g++ *.cpp -o prog" will do all that for you, but that's not the command that CodeRunner uses: it just compiles the one explicitly-named program. So you would need to modify CodeRunners compile-and-link command.

However, if you tell the students to #include both the .h and any .cpp files in the main program, then you don't need to separately compile the .cpp files. It's unorthodox, and rather defeats the point of having .h files but it works OK. It sounds like that's what you must be doing.