This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why can not use reference in operator function?


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]