本文介绍了“无法调用成员函数...无对象”内部未评估的上下文 - GCC错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下程序使用Clang编译正常:
The following program compiles fine with Clang:
template< typename > struct X { void foo() {} auto bar() -> decltype( X::foo() ) { return foo(); } }; int main() { X<int>().bar(); }但GCC 4.8.1提供:
But GCC 4.8.1 gives:
main.cpp: In instantiation of 'struct X<int>': main.cpp:13:10: required from here main.cpp:5:34: error: cannot call member function 'void X< <template-parameter-1-1> >::foo() [with <template-parameter-1-1> = int]' without object auto bar() -> decltype( X::foo() ) ^ main.cpp: In function 'int main()': main.cpp:13:12: error: 'struct X<int>' has no member named 'bar' X<int>().bar(); ^活动示例
当我将代码更改为 decltype(std :: declval< X>()。foo()) GCC编译它。
When I change the code to decltype( std::declval<X>().foo() ) GCC compiles it.
推荐答案
可能有的错误报告了吗?这个bug? decltype需要在模板类的成员函数声明中使用明确的this指针,尾随返回类型为 - dyp
Possibly this bug? decltype needs explicit 'this' pointer in member function declaration of template class with trailing return type – dyp
修正。
更多推荐
“无法调用成员函数...无对象”内部未评估的上下文
发布评论