| 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
.
|
|
|
|

|
Related Articles |
|
|