This is the mail archive of the gcc@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]

Re: error in g++ error report


>>>>> «Nelson», Nelson Jose dos Santos Ferreira <Nelson.Ferreira@inesc.pt> écrit :

Nelson> On Tue, 2 Sep 1997 11:47:10 +0200 (MET DST), Gabriel Dos Reis (aka "Gabriel"),
Nelson> regarding 'Re: error in g++ error report', said: 

Nelson> You should have declared A(A&) then.
Gabriel> Did you read the code I included ?

Nelson> Not on my second reply.


	Here it is:


class A {
public:
    A() {}
    A(A&) {}
};

int main()
{
    const A a;
    A b = a;
}


Gabriel> The draft is clear. If you do not declare a copy constructor
Gabriel> then the compiler generate one with bitwise copy semantic, whose
Gabriel> signature is:

Gabriel> A(const A&)

Gabriel> If at least one copy constructor is declared then it overrides the
Gabriel> default one unless it is defined. I am afraid you didn't get the
Gabriel> purpose of the code. Please read Alexandre Oliva's reply.

Nelson> How does this conflict with my answer ? I only said one answer would be for
Nelson> you to declare the copy constructor as private. Then the compiler will not
Nelson> generate the bitwise copy constructor!


	You 're right in saying that, but the compiler is wrong in
attempting to generate a copy constructor since there is already one!
If it is not suitable then it must give up with an appropriate
error-message. Take a look at the CD2 section 12.8.


Nelson> Probably I didn't get the purpose.

	My purpose was to see how g++ does handles this case. If I
want to initialize with non-const objects (but not with const objects)
then I can define only A(A&) and live A(const A&) not delcared. I do
not have to declare A(const A&) private. I should to so if no copy
constructor were declared

Best,

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]