gpt4 book ai didi

c++ - 如何使用带有模板的本地类?

转载 作者:太空狗 更新时间:2023-10-29 19:47:11 26 4
gpt4 key购买 nike

GCC 似乎不赞成使用本地类实例化模板:

template <typename T>
void f(T);

void g()
{
struct s {};

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

VC 不会提示。

应该怎么做?

最佳答案

在 C++03 中无法完成,C++0x 可以 lift不过这个限制。

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.

关于c++ - 如何使用带有模板的本地类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3172909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com