类成员变量的Decltype是否被禁止?为什么
decltype of a class member variable, is it forbidden? Why?
我可以写
int a;
decltype(a) b;
但是我的编译器(Microsoft Visual Studio 2010, cl
Version 16.00.40219.01)禁止我
class A
{
int a;
decltype(a) b;// error C2327: 'A::a' : is not a type name, static, or enumerator
};
也comau C/c++ 4.3.10.1 (Oct 6 2008 11:28:09)对于ONLINE_EVALUATION_BETA2给出了类似的错误。
"ComeauTest.c", line 7: error: a nonstatic member reference must be relative to a
specific object
decltype(a) b;
^
这种行为的基本原理是什么?
是有效的。在未求值的操作数(decltype
, sizeof
, noexcept
,…的操作数)中,也可以在成员函数之外命名非静态数据成员。
你尝试过的编译器还不支持这个特性
相关文章:
- 为什么我会收到此警告:ISO c++ 禁止可变长度数组"v"[-Wvla]
- 当空基类也是成员变量时,为什么禁止空基优化?
- 为什么禁止建造 istreams?
- "Empty base optimization" lambda 捕获 - 标准禁止?为什么?
- 为什么std::变体中禁止引用
- 为什么 C 与 C++ 相反,禁止在指针到指针的两个级别添加 const 限定
- C :为什么禁止递归模板别名
- 为什么默认成员值禁止使用支持列表初始化
- 为什么ISO C++标准禁止对成员进行初始化
- 为什么禁止c++中的静态分配
- 为什么隐式"lambda to function pointer conversion"禁止"by reference"捕获静态成员?
- C++ 外部类访问 内部类为什么被禁止
- 为什么数组形式参数总是隐式转换为指针而不是被禁止
- 为什么禁止在 mac 中使用没有 exec 的 fork
- 为什么 ISO C++禁止返回数组
- 为什么禁止对位域进行非常量引用
- 为什么C++禁止新的T[n](arg..)
- 为什么C++禁止声明没有类型的参数
- 为什么标准禁止部分专门化的友元声明
- 类成员变量的Decltype是否被禁止?为什么