By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

why is automatically generated copy constructor of this form

P: n/a
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

Dec 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
puzzlecracker wrote:
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.

Dec 15 '05 #2

P: n/a

Neelesh Bodas wrote:
puzzlecracker wrote:
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.


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

Dec 15 '05 #3

P: n/a
puzzlecracker wrote:
Neelesh Bodas wrote:

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.


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.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Dec 26 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.