The following code compiles perfectly:
// MyFile.h
#ifndef MYFILE_H_INCLUDED
#define MYFILE_H_INCLUDED
template
class MyClass
{
If you include the MyFile.tpp
(I renamed it from .cpp), then you don't need to include the MyFile.h
. #include
ing a file is like exactly copying it's content into the file where it's included. Other from that, it's a common practice to organize the headers a bit. (Though you don't need the include-guards in the MyFile.tpp
, because it should only ever be included from another header directly (like GMan says).)
Note: Because the file is a *.tpp file (not *.cpp) it should not be included by other build system operations. If you have added it manually remove it.
Make sure the only place that includes <X>.tpp is the last line in <X>.h