Why hiding copy-constructorin polymorphic classes?

R

Roal Zanazzi

Hi all,

I'm reading (sloooowly, time permitting) "Modern C++ Design" by
Alexandrescu.

In chapter 2.4 "Mapping Integral Constants to Types" (but this is not
directly related to my question) the author writes:
"... T has disabled its copy constructor (by making it private) as a
well-behaved polymorphic class should."

I'm trying to grasp all the possible implications involved in this
design choice, but I need an expert's direction.

Could you explain the problem(s) involved?

TIA
 
V

Victor Bazarov

Roal said:
I'm reading (sloooowly, time permitting) "Modern C++ Design" by
Alexandrescu.

In chapter 2.4 "Mapping Integral Constants to Types" (but this is not
directly related to my question) the author writes:
"... T has disabled its copy constructor (by making it private) as a
well-behaved polymorphic class should."

I'm trying to grasp all the possible implications involved in this
design choice, but I need an expert's direction.

Could you explain the problem(s) involved?

Not sure what author means. I never thought [before] that a "well-
behaved polymorphic class" "should" disable its copy-constructor.
Perhaps it's a reference to the fact that any "well-behaved" class
of that nature should only be constructed by a special "factory",
and as such it should definitely prohibit inadvertent copying. All
copying should probably be done using its "clone" method or some
such.

V
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top