03-16-2018, 08:41 PM
(This post was last modified: 03-16-2018, 09:29 PM by Brian Beuken.)
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,
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 a 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?
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 a 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?
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's