简体   繁体   English

用于模板实例化的Clang / g ++选项

[英]Clang/g++ options for template instantiation

I'm looking for a compiler option on g++/clang++ to control the instantiation of methods in explicit instantiations. 我正在寻找g ++ / clang ++上的编译器选项,以控制显式实例化中方法的实例化。

Suppose I have a classtemplate Foo<T> with some explicit instantiation 假设我有一个带有一些显式实例化的类模板Foo<T>

template Foo<int>;

I want to enable the instantiation of all public methods. 我想启用所有公共方法的实例化。 This doesn't seem to be the default, as I'm having to add manual instantiations for all the members in order to avoid link errors; 这似乎不是默认设置,因为我必须为所有成员添加手动实例化以避免链接错误。

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

You can either instantiate each method individually or you would instantiate all of them for the class. 您可以单独实例化每个方法,也可以为该类实例化所有方法。 It seems you want to do the latter but the notation you tried is wrong. 似乎您想做后者,但是您尝试的表示法是错误的。 The correct one is this: 正确的是这样的:

template class Foo<int>;

(assuming Foo is declared as a class ; if it is declared as a struct you'd use the struct keyword instead). (假设Foo被声明为class ;如果将其声明为struct ,则应使用struct关键字)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM