“无法调用成员函数...无对象”内部未评估的上下文

编程入门 行业动态 更新时间:2024-10-19 11:51:28
本文介绍了“无法调用成员函数...无对象”内部未评估的上下文 - 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

修正。

更多推荐

“无法调用成员函数...无对象”内部未评估的上下文

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

发布评论

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

>www.elefans.com

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