C++泛型类的.h与.cpp

原文

http://www.codeproject.com/Articles/48575/How-to-define-a-template-class-in-a-h-file-and-imp(不正确)


http://blog.ethanlim.net/2014/07/separate-c-template-headers-h-and.html (正解)


Solution 1:All implementation into the header file

Quote from The C++ standard library: a tutorial and handbook:

The only portable way of using templates at the moment is to implement them in header files by using inline functions.


Solution 2:Explicit Template Instantiation

将Template Instantiation放到实现cpp中

template class Foo;
template class Foo;

但是,template class Foo需要额外声明

你可能感兴趣的:(CC++)