Why can not use reference in operator function?

Jonathan Wakely jwakely.gcc@gmail.com
Tue Nov 26 13:41:00 GMT 2013


On 26 November 2013 13:17, Parmenides wrote:
> Hi Wakely,
>
> Thanks for your reply. The code has gotten compiled successfully with
> both compliers. I wonder what is the difference between 'Int &' and
> 'const Int &'.

That is a basic C++ question, so is not suitable for this mailing
list. See http://www.parashift.com/c++-faq/ref-to-const.html

> Why the former fails,  while the latter causes the
> conversion from an 'int' to an 'Int' object?

Again, this mailing list is not the right place to try and learn C++.

The conversion from int to Int creates a temporary object, and
temporary Int objects cannot bind to Int& references, they can only
bind to const Int& reference. That's how C++ works.



More information about the Gcc-help mailing list