473,394 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

why is automatically generated copy constructor of this form

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
3 1567
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
2
by: lovecreatesbeauty | last post by:
I'm disturbed on this question on a long time. I think if I finally get understand it with your kind help, I will get close to a excellent C++ programmer. And I only can rely on your expertise and...
4
by: moleskyca1 | last post by:
Hi, In a recent discussion, some of us were in disagreement about the functions the C++ compiler generates. How many functions are generated by the compiler when you declare: class Foo { };...
13
by: cj | last post by:
In a project done in 2003 about a year ago I was told to add the SocketWrench code below into the Windows Form Designer generated code area as shown below. #Region " Windows Form Designer...
6
by: JohnQ | last post by:
I like, non-copyable, non-assignable and, most often, non-default-constructable also, as a starting point for class design: class SomeClass { SomeClass(); // disallow default construction...
43
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because...
3
by: subramanian100in | last post by:
I thought the copy ctor always takes the form Test::Test(const Test & arg); for a class Test. But I read the following sentence in Stanley Lippman's C++ Primer 4th Edition(Page 476): The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.