本地类型作为C ++中的模板参数 [英] Local type as template arguments in C++

查看:106
本文介绍了本地类型作为C ++中的模板参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

#include <vector>
template <typename T, template<typename> class C = std::vector >
struct FooBar
{
   /*codez*/
};
template<typename T>
struct Global{};

int main()
{
   struct Local{};  
   FooBar<Local,Global> k;
}

这是我得到的错误

类C> struct FooBar'使用本地类型'main():: Local'

标准的哪一部分说这是错误的?我使用gcc 4.5.1。

Which part of the standard says that this is wrong? I am using gcc 4.5.1. How can make this code work?

推荐答案


标准的哪一部分说这是错误的?

Which part of the standard says that this is wrong?

这将是2003 C ++标准的§14.3.1/ 2:

That would be §14.3.1/2 from the 2003 C++ Standard:


本地类型,没有链接的类型,未命名类型或从这些类型中任何一个复合的类型都不能用作模板参数模板类型参数








如何使此代码正常工作?

How can make this code work?

不要使用本地类型作为模板参数。

Don't use a local type as a template argument.

请注意,这个限制已在C ++ 11中解除,因此使用该语言标准,您可以使用本地类型作为模板参数。

Note that this restriction has been lifted in C++11, so using that language standard you are able to use a local type as a template argument.

这篇关于本地类型作为C ++中的模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆