-
Classes and header files
I recently purchased SAMS Teach Yourself C++ In 21 Days and it says that i should put classes in a header(.h or .hpp) file but have the class functions in a .cpp file, why is this? and wouldn't it be easier to write the functions in the header file along with the class?
-
This is to hide the implementation of the class. For the user of the class, all he would need to know is how to use the class from looking at the header definition only. This way, commercial applications can give the user the user interface only while keeping the implementation proprietary.
-
I'm not sure I understand, would you be able to explain that in simple terms please? Also, how could the user look at the header files if the program is compiled? (unless I gave out the source code).
-
Search for math.h on your hard drive. When you open it up you'll be able to see all the functions you are able to use but not how they are implemented. It prevents people from nicking code and passing it off as their own