Re: Why can not use reference in operator function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux