Problem using multiple .cpp and .h files in one project

Here's an issue that I've found incredibly irritating since it has nothing to do with coding errors, but rather what my IDE is doing.

Basically I have main.cpp, then two classes, each of which has a .h and a .cpp. At the top of each .cpp file I've added the #include "theheader.h" statements for each class.

Everything I put in the header files works (ie. inline function stuff), but any time I try to use the code in the other .cpps in main.cpp, it throws:

undefined reference to 'Class::Function()'

I know this has got to be such a dumb error, but help would be much appreciated.
Last edited on
closed account (zb0S216C)
Sounds like you haven't included the files into your project.

You may not use inline functions across cpp files like that.
An inline function -must- be defined where it is declared. Otherwise you'll get an unresolved external error in your build.

If your compiler is not from the stone-age, you may not want to explicitly declare your function inline anyway. It should optimize your code. Declaring it inline only -hints- it to be inline, it doesn't guarantee it. (at least in the MSVC compiler)
Last edited on
Thanks frame, for some reason all but one of the files were added. It explains a lot.
Topic archived. No new replies allowed.