Template classes and include guards in C++

c++, include-guards, templates

Solution

Templates definitions are supposed to be parsed once (and things like two phases name lookup are here so that as much errors as possible can be given immediately without having an instantiation). Instantiations are done using the internal data structure built at that time.

Templates definitions are usually (i.e. if you aren't using `export` or doing something special) in header files which should have their include guard. Adding one for template definition is useless but not harmful.

Problem

Is it wise to have include guards around template classes? Aren't template classes supposed to be reparsed each time you reference them with a different implementation? N.B In Visual C++ 2008 I get no errors combining the two...

Original source

Related problems