How to use local classes with templates?

萝らか妹 提交于 2019-12-17 20:54:40

问题


GCC doesn't seem to approve of 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?


回答1:


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.



来源:https://stackoverflow.com/questions/3172909/how-to-use-local-classes-with-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!