C++ 无法重载对*此的引用

C++ 无法重载对*此的引用,c++,c++11,reference,this,rvalue,C++,C++11,Reference,This,Rvalue,下面是我编写的一个busybox,用于处理N2439的gcc-4.8.1+中的新功能(我认为clang-2.9+也应该这样做)(参考“this”的限定符): 在阅读标准8.3.5时,我认为三个bar()方法应该是可重载的。但我收到一个链接器错误: [ed@localhost ref_this]$ ../bin/bin/g++ -std=c++11 -o ref_this ref_this.cpp /tmp/ccwPhzqr.s: Assembler messages: /tmp/ccwPhzqr

下面是我编写的一个busybox,用于处理N2439的gcc-4.8.1+中的新功能(我认为clang-2.9+也应该这样做)(参考“this”的限定符):

在阅读标准8.3.5时,我认为三个bar()方法应该是可重载的。但我收到一个链接器错误:

[ed@localhost ref_this]$ ../bin/bin/g++ -std=c++11 -o ref_this ref_this.cpp
/tmp/ccwPhzqr.s: Assembler messages:
/tmp/ccwPhzqr.s:73: Error: symbol `_ZN3Foo3barEv' is already defined
如果我注释掉
int bar()常量&
我无法解析
ff.bar()

这是gcc错误还是标准的一部分


我的电脑上没有叮当声,但叮当声说了什么?

4.8.0版之前的GCC不支持此功能,目前还没有正式发布


据我所知,目前唯一支持成员函数引用限定符的主要编译器是Clang。正如您从中看到的,您的代码在Clang3.2上编译得很好。

这是对g--4.8.1和gcc trunk的引用。我知道这个版本是潮湿的,没有多少人拥有它,但它确实存在。你的LWS示例显示了一系列错误。这是gcc吗?你也有叮当的版本吗?谢谢,我看到了。我会查一下LWS。我认为IDEone有相当老的GCC。@ EMSR:IDENN和LWS都有C++ 11的GCC 4.7.2,虽然LWS也有一组其他C++编译器。@ XEO谢谢,我很高兴他们发现了版本。我得试试我的一些测试。对于那些不知道这是怎么回事的人。
[ed@localhost ref_this]$ ../bin/bin/g++ -std=c++11 -o ref_this ref_this.cpp
/tmp/ccwPhzqr.s: Assembler messages:
/tmp/ccwPhzqr.s:73: Error: symbol `_ZN3Foo3barEv' is already defined
[ed@localhost ref_this]$ ../bin/bin/g++ -std=c++11 -o ref_this ref_this.cpp
ref_this.cpp: In function ‘int main()’:
ref_this.cpp:26:10: error: no matching function for call to ‘Foo::bar() const’
   ff.bar();
          ^
ref_this.cpp:26:10: note: candidates are:
ref_this.cpp:11:7: note: int Foo::bar() &
   int bar() & { return _M_i /= 2; }
       ^
ref_this.cpp:11:7: note:   no known conversion for implicit ‘this’ parameter from ‘const Foo’ to ‘Foo&’
ref_this.cpp:13:7: note: int Foo::bar() &&
   int bar() && { return 2 * _M_i; }
       ^
ref_this.cpp:13:7: note:   no known conversion for implicit ‘this’ parameter from ‘const Foo’ to ‘Foo&&’