类成员变量的十进制类型,是否被禁止?为什么? [英] decltype of a class member variable, is it forbidden? Why?

查看:88
本文介绍了类成员变量的十进制类型,是否被禁止?为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会写

  int a;decltype(a)b; 

但是我的编译器(Microsoft Visual Studio 2010, cl 版本16.00.40219.01)禁止我

  A类{诠释decltype(a)b;//错误C2327:'A :: a':不是类型名称,静态或枚举器}; 

针对ONLINE_EVALUATION_BETA2的Comeau C/C ++ 4.3.10.1(2008年10月6日11:28:09)也给出了类似的错误.

 "ComeauTest.c",第7行:错误:非静态成员引用必须相对于具体对象decltype(a)b;^ 

此行为的依据是什么?

解决方案

是的.在未求值的操作数( decltype sizeof noexcept 等)中,您也可以在成员函数之外命名非静态数据成员./p>

您尝试过的那些编译器尚不支持此功能.

I can write

int a;
decltype(a) b;

but my compiler (Microsoft Visual Studio 2010, cl Version 16.00.40219.01) forbid me

class A
{
   int a;
   decltype(a) b;// error C2327: 'A::a' : is not a type name, static, or enumerator
};

Also Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2 gives a similar error.

"ComeauTest.c", line 7: error: a nonstatic member reference must be relative to a
          specific object
     decltype(a) b;
              ^

What is the rationale for this behaviour?

解决方案

Yes that is valid. Within unevaluated operands (operands of decltype, sizeof, noexcept, ...) you can name nonstatic data members also outside of member functions.

Those compilers you tried just don't support this feature yet.

这篇关于类成员变量的十进制类型,是否被禁止?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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