include .h or .cpp file?
If a person has created a class they have 2 files: the .h file (header file?) and the .cpp file (implementation file?)
Now to use the class in a main file, should the the .h file be included (which in turn includes the implementation file) or vice-versa? Different people I ask give me different answers.
Never include a .cpp file.
The only possible sticky point is if you have template code, since that code needs to be visible. OTOH, there are lots of extensions that aren't ".cpp" you can use for such code, so really the rule is still: Never include a .cpp file. AND ALSO: The statement that the .h file include the implementation file is also greatly mistaken.
Originally Posted by tabstop
So always include the header file unless it is templated, in which case include the implementation file or use an alternative solution? Why do you say that the header file including the implementation file is a misconception? is it because it should be including the object code of the implementation file or am I getting confused?
Implementation files include headers. In the case of templates you have to break the rule if you want your source and header in sep. files but even then they usually have an .hpp, .inl, or some other extension. I prefer .hpp.
Header files do not include implementation except for the aforementioned template exception.