HELP ME

C

Chris ( Val )

CAN ANYBODY TELL ME THE CONCEPT OF COPY CONSTRUCTOR IN REALLY SINMPLE
MANNER

Please do not use your CAPS LOCK when asking questions, as it
is considered as shouting and being rude.

The simple answer is, it makes copies :)

A class in C++ provides you with a copy ctor by default. Even
though you can't physically see it, it does exist.

The only time you need to manually implement it is for example,
if your class is is responsible for managing some memory for one
or a number of its data members.

The best way to learn about it is to experiment.

Looking up "deep copy" vs "shallow copy" should provide you with
a much better understanding of the concepts behind it.

Post back if you're still having problems understanding it, and
we'll try to clarify it further.
 
M

Mike Wahler

aman said:
CAN ANYBODY TELL ME THE CONCEPT OF COPY CONSTRUCTOR IN REALLY SINMPLE
MANNER

[waiting for ringing in my ears (eyes?) to stop]

Constructor: Initializes a newly created object
to a known state.

Copy constructor: Initializes a newly created object
with a state equal to that of an already existing
object of the same type (i.e. it makes a copy of
an existing object).

What C++ book are you reading that doesn't explain this?
Perhaps you need a better one. See www.accu.org for
peer reviews and recommendations.

-Mike
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top