简体   繁体   中英

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.

Suppose I have a classtemplate Foo<T> with some explicit instantiation

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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