我正在阅读类型擦除:
我在哪里遇到以下文字:
除非您可以提前枚举模板的所有实例,否则您必须在头文件中包含每个函数模板的主体,您不能将声明与实现分开
枚举模板的所有实例化是否与回答以下问题时指出的显式实例化相同?
另一种解决方案是保持实现分离,并显式实例化您需要的所有模板实例:
// Foo.h
// no implementation
template <typename T> struct Foo { ... };
//----------------------------------------
// Foo.cpp
// implementation of Foo's methods
// explicit instantiations
template class Foo<int>;
template class Foo<float>;
// You will only be able to use Foo with int or float