Re: const references : confusion



 DEVELOP > c-Plus-Plus > Re: const references : confusion

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Murali"
Date: 12 Feb 2004 09:35:17 PM
Object: Re: const references : confusion


Why should i need to add the 'const' keyword here?

Besides other reasons,
A non const reference allows operator = to modify
the object which is the right hand side of =. To prevent
this C++ requires a const reference.
.

User: "John Harrison"

Title: Re: const references : confusion 13 Feb 2004 12:41:19 AM
"Murali" <srimat@ameritech.net> wrote in message
news:VBXWb.2142$t16.1697207@newssvr28.news.prodigy.com...



Why should i need to add the 'const' keyword here?

Besides other reasons,
A non const reference allows operator = to modify
the object which is the right hand side of =. To prevent
this C++ requires a const reference.

Not true..
T& operator=(T&) is a legal assignment operator. It is not a good idea most
of the time but it is legal.
It's used exactly when an assignment operator does need to modify the rhs of
=, for instance look at std::auto_ptr.
In the same way T(T&) is a legal copy constructor.
john
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER