C++11 decltype of member
C++11 decltype of member
为什么我不能这样做:
class Foo {
void fn();
using fn_t = decltype(fn); //call to non-static member function without an object argument
};
但我可以做
class Foo {
static void fn();
using fn_t = decltype(fn);
};
此SO帖子声称:
在未赋值的操作数(decltype、sizeof、noexcept等操作数)中,您可以命名成员函数之外的非静态数据成员
fn
是表示非静态成员函数的有效id表达式。§5.1.1【expr.prim.general】/p13(省略脚注):
表示非静态数据成员或非静态的id表达式只能使用类的成员函数:
- 作为类成员访问(5.2.5)的一部分,其中对象表达式引用成员的类或从该类派生的类类,或
- 形成指向成员(5.3.1)的指针,或
- 如果id表达式表示非静态数据成员,并且它出现在未赋值的操作数中
§7.1.6.2[dcl.类型.简单]/p4:
decltype
说明符的操作数是未赋值的操作数(第5条)。
由于decltype
不是少数可以使用表示非静态成员函数的id表达式的上下文之一,因此程序格式不正确。
相关文章:
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 收到错误"invalid use of non-static data member 'stu::n' "
- Centos7 g++ "to_string is not in a member of std"
- C++ "Invalid use of 'this' in non-member function" ,
- 出现这种错误的原因是什么"invalid use of non-static data member "
- 当我编译XG-Bosst时,出现错误"error: 'Split' is not a member of 'xgboost::common' ……"
- 为什么这句话"The expression can be used only as the left-hand operand of a member function call"在 [expr.re
- "Default member initializer needed within definition of enclosing class outside of member functions
- 如何修复库中的"invalid use of non-static member function" 导入另一个库
- C++ 小错误:"... is not a static data member of ‘class ...'"
- 在 c++ 中获取"is not a static member of class"错误
- 尝试使用 SFLM 顶点时出错:"Vertex is not a member of sf"
- Visual Studio: "str() is not a member of std::ostringstream"
- 重载的'dereference'或'member of pointer'运算符在我有指向对象的指针时不会运行
- VC++ 2010 "array is not a member of std"错误
- LNK2001 "How can I make a WNDPROC or DLGPROC a member of my C++ class?"
- 开发C++ "to_string is not a member of std"错误
- "is not a member of"和"no matching function for call to"错误
- 获得"error C2039: 'value_type' : is not a member of 'std::greater<_Ty>'"
- 我在我的编程实验室中收到错误"stoi is not a member of std"