03-16-2018, 09:08 PM
(03-16-2018, 08:41 PM)Brian Beuken Wrote: hmmm see that question makes me worry that you still have a little bit to learn on the basics of C++ and this might be a bit too much for you at the moment,Well yes. So when I include xxx.h, xxx.cpp is included also for compiling?
But i will do my best to help, I would like to know if you can cope with it.
All the CPP files in your solution are compiled by the gcc compiler. each cpp file if successfully compiled produces an obj file of the same name
If all files compile, the linker then links all obj files and if all is correct produces the executable file.
Now an classname.H or header file, contains the definition of a class, and the classname.cpp file needs that to make sure that it has properly built the class as the definition requires.
Other cpp files might need to know or create an instance of a class which is contained in another CPP/OBJ file, so it includes the definition of the class as an include file.h
That then tells the compiler, what kind of class object it expects, what its methods and members are, and lets the compiler produce the obj file. And again, the linker makes sure that you are using the values correctly and if all ok, patches in the address to find the methods and members.
So while MyFiles.cpp uses the Myfiles.h header to correctly produce the class code,
Your main.cpp or game.cpp file, only need to include the MyFiles.h so they know what a MyFiles class is, if they want to make one as part of the code in main, or game.
Does that help?
I included myfiles.h in the game.cpp and it did compile now without errors but I get an error when executing that the image file can not be loaded...
I will first reread my c and c++ books before I continue.
Thanks for your help.