RE: Copy constructor with non const rhs arg

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

 



(I sent this earlier to Paul but forgot to CC the list...)

I believe the problem here is that "test dd = foo()" is using a
temporary object (returned by foo).  You cannot pass a non-const
reference to that temporary object into test's copy constructor.
Temporary objects are always "const".

You can, of course, pass a const reference to a temporary object.

Similarly, if foo() returns a reference, that reference must point to a
valid (not temporary) object, so passing a reference to THAT object into
test's copy constructor is just fine.

So I think gcc's behavior is correct (though the error text is a bit
unclear).  I don't know what Microsoft's compiler is doing in that case,
but it seems unusual and could probably lead to bad behavior.

---
Tony Wetmore
Raytheon Solipsys
mailto:tony.wetmore@xxxxxxxxxxxx
http://www.solipsys.com
 
 


-----Original Message-----
From: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx] On
Behalf Of Eljay Love-Jensen
Sent: Wednesday, May 12, 2004 12:05 PM
To: paul moore; gcc-help@xxxxxxxxxxx
Subject: Re: Copy constructor with non const rhs arg


Hi Paul,

I believe a copy constructor requires a const parameter.

But I may be mistaken.  I've been mistaken before.

You can make the auto_ptr member variable mutable.

--Eljay



[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