I saw some code in which the developer defined a class template in a .h file, and defined its methods in a .hpp file. This caught me a bit by surprise.
Are there are particular conventions in C++ when dealing with templates and what files they should be in?
For example say I had a Vector class template with methods for vector operations (add, subtract, dot, etc.). I would also want to specialize certain functions if the template argument is a float (comparison operators). How would you separate all of this between files (specify whether .h, .hpp, .cpp).
Typically (in my experience, YMMV) an
hppfile is an#include-ed CPP file. This is done in order to break the code up in to two physical files, a primary include and an implementation-details file that the users of your library don’t need to know about. It is done like this:super_lib.h (the only file your clients need to
#include)super_lib_implementation.hpp (your clients do not
#includethis directly)