why is automatically generated copy constructor of this form

P

puzzlecracker

Given,

class X
{
//.....

private:
auto_ptr<Y> y;

};

In this example, if we try to

X a;
X b(a);

or

a=b;
X::(X&); constructor will be generated (assignment operator
respectively)? why? Shouldn't be X::(const X&) or suit is followed
due to auto_ptr copy constructor of that non-const form?

I thought non-const form wasn't an standard definition of automatically
generated copy constructer.

Thanks
 
N

Neelesh Bodas

puzzlecracker said:
Given,

class X
{
//.....

private:
auto_ptr<Y> y;

};

In this example, if we try to

X a;
X b(a);

or

a=b;
X::(X&); constructor will be generated (assignment operator
respectively)? why? Shouldn't be X::(const X&) or suit is followed
due to auto_ptr copy constructor of that non-const form?

I thought non-const form wasn't an standard definition of automatically
generated copy constructer.

<quote>
12.8p5:
The implicitly declared copy constructor for a class X will have the
form
X::X(const X&) if
- each direct or virtual base class B of X has a copy constructor
whose first parameter is of type const B& or const volatile B&, and
- for all the nonstatic data members of X that are of a class type M
(or array thereof), each such class type has a copy constructor whose
first parameter is of type const M& or const volatile M&.107).

Otherwise, the implicitly declared copy constructor will have the form
X::X(X&)
An implicitly declared copy constructor is an inline public member of
its class.
</quote>

Hope this helps.
 
P

puzzlecracker

Neelesh said:
<quote>
12.8p5:
The implicitly declared copy constructor for a class X will have the
form
X::X(const X&) if
- each direct or virtual base class B of X has a copy constructor
whose first parameter is of type const B& or const volatile B&, and
- for all the nonstatic data members of X that are of a class type M
(or array thereof), each such class type has a copy constructor whose
first parameter is of type const M& or const volatile M&.107).

Otherwise, the implicitly declared copy constructor will have the form
X::X(X&)
An implicitly declared copy constructor is an inline public member of
its class.
</quote>

Hope this helps.

I suspected that, but never *bothered* looking into the standard. thx.
 
P

Pete Becker

puzzlecracker said:
I suspected that, but never *bothered* looking into the standard. thx.

Note that that's the technical explanation of what the compiler did. It
doesn't address the problems you'll run into when copying objects that
hold auto_pointer objects. General advice: don't do it. Too many headaches.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top