This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: non-const copy ctor
- From: John Love-Jensen <eljay at adobe dot com>
- To: Christian Fröbel <cfroebel at web dot de>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Fri, 07 Apr 2006 21:22:15 -0500
- Subject: Re: non-const copy ctor
Hi Christian,
> Hmm, I would say *usually* it is a const reference.-- But eventually it is
> not, like in my case or in the case of std::auto_ptr.
In C++, a copy constructor is a const reference.
> Of course you could say this isn't a copy constructor because it doesn't take
a const reference.
It's not a copy constructor.
> But I think it is anyway because it still has the semantic of a copy
operation.
Regardless, it's not a copy constructor.
> Anyway, I need to have a constructor taking a non-const reference which g++
> doesn't allow.
You can implement similar facilities like auto_ptr for your class to have
the behavior you are inquiring about.
> And I still don't know why g++ is acting this way here and how to work around
it.
On this particular issue, g++ is complying with ISO 14882. VC7 is not.
More information in The Design and Evolution of C++:
http://www.amazon.com/gp/product/0201543303/
I don't recall if the particular point you raised is covered.
I believe it (copy constructor being a const reference) has to do with
catastrophic slicing if it were not a const, and infinite recursion if it
were not a reference.
Sincerely,
--Eljay