Difference between revisions of "User talk:SteveBaker"
|(18 intermediate revisions by 3 users not shown)|
|Line 1:||Line 1:|
Latest revision as of 08:40, 23 October 2010
So here we have the "header file" called MyClass.h - which contains the declaration of MyClass - and all of the really simple functions (maybe everything under 5 or so lines long is a good rule of thumb). Every ".cpp" file that implements or uses MyClass has to #include this header file. For the very simplest classes, you may not need a ".cpp" file - in which case you can just leave it out.
Each "MyClass.cpp" file must #include (at a minimum) the MyClass.h file so that it can 'see' the class definition at compile time...but it also has to #include the header files for all of the classes that it references (including system headers for classes such as I/O, math, etc). However, in a complicated program with dozens to hundreds of classes, it can get really hard to remember all of the header files you need - and there is always a half dozen system header files to include (things like 'iostream' that declares std::cout for example). Hence, a common thing is to make a 'main.h' header that includes all of the other headers - so you only have to remember to stick a '#include "main.h"' at the top of every .cpp file - and you're good to go.
Then we have MyClass.cpp which contains the implementation of the function "AReallyReallyComplicatedFunction" - and we have "main.cpp" that contains our main program. Usually, this file is named after the program itself rather than "main" - so if this is MyFirstVideoGame then we'd probably call the files "MyFirstVideoGame.h" and "MyFirstVideoGame.cpp".