开发者

How to use local classes with templates?

开发者 https://www.devze.com 2023-01-05 20:23 出处:网络
GCC doesn\'t seem to approve o开发者_开发知识库f instanciating templates with local classes: template <typename T>

GCC doesn't seem to approve o开发者_开发知识库f instanciating templates with local classes:

template <typename T>
void f(T);

void g()
{
    struct s {};

    f(s()); // error: no matching function for call to 'f(g()::s)'
}

VC doesn't complain.

How should it be done?


In C++03 it can't be done, C++0x will lift that restriction though.

C++03, §14.3.1/2:

A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template-argument for a template type-parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消