没有匹配的函数调用< anonymous enum>

编程入门 行业动态 更新时间:2024-10-24 06:27:06
本文介绍了没有匹配的函数调用< anonymous enum>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

给定:

模板< typename T& void f(T){} enum {//如果更改为enum Eit it compiles e } int main(){ f(e); // line 10 }

我得到:

foo.cpp:在函数'int main()': foo.cpp:10:错误:没有匹配的函数调用'f ; anonymous enum>)'

但如果枚举声明给出一个名字,它编译。为什么它不适用于匿名枚举?理想情况下,我想把枚举值 e 提升为 int ,并实例化未命名的类型不能用作模板参数

>

C ++ 03在中说14.3.1 [temp.arg.type] / 2

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

这个限制在C ++ 0x中解除了,你的程序编译时没有MSVC ++ 2010和gcc 4.5的诊断。 2在C ++ 0x模式下。

Given:

template<typename T> void f( T ) { } enum { // if changed to "enum E" it compiles e }; int main() { f( e ); // line 10 }

I get:

foo.cpp: In function ‘int main()’: foo.cpp:10: error: no matching function for call to ‘f(<anonymous enum>)’

Yet if the enum declaration is given a name, it compiles. Why doesn't it work for an anonymous enum? Ideally, I'd like it to promote the enum value e to an int and instantiate f(int).

解决方案

Unnamed type simply cannot be used as a template argument

C++03 says in 14.3.1[temp.arg.type]/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.

This limitation was lifted in C++0x, and your program compiles with no diagnostics with MSVC++ 2010 and gcc 4.5.2 in C++0x mode.

更多推荐

没有匹配的函数调用&lt; anonymous enum&gt;

本文发布于:2023-11-11 06:57:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577697.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   amp   lt   gt   enum

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!