2015-07-12 51 views
1

选项我正在寻找在G ++ /铛++编译器选项来控制的显式实例方法的实例。锵/ G ++模板实例

假设我有一个classtemplate Foo<T>一些显式实例

template Foo<int>; 

我想启用的所有公共方法的实例。这似乎并不为默认,因为我不必手动添加为实例,为了避免链接错误全体成员;

template void Foo<int>:DoStuff(int); 
template int Foo<int>:GetSomeStuff(); 
+0

'模板富'没有做任何事情(它实际上是在海湾合作委员会的错误)。你想'模板类Foo '。 – 0x499602D2

回答

2

您可以单独实例化每个方法,也可以为类实例化所有方法。看来你想要做后者,但你尝试过的符号是错误的。正确的是:

template class Foo<int>; 

(假设Foo声明为class;如果它被声明为struct你使用struct关键字代替)。