error in g++ error report
Gabriel Dos Reis
Gabriel.Dos-Reis@dptmaths.ens-cachan.fr
Tue Sep 2 03:24:00 GMT 1997
>>>>> ë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
More information about the Gcc
mailing list