pankajrg said:
why there is a need of eplicitly defining the copy constructor.
please correct me, Is it true that copy constructor are created by
compiler, by default
if we don't create copy constructor.
Yes, the copy ctor is indeed generated for you. Often enough, but not
always, is that acceptable.
Lets put it this way.
You want to copy an exact replica of the house your neighbour has. You
love that house so much you want every detail to be exactly the same.
So you let a default copy constructor replicate the new home for you -
bit by bit, brick by brick. Great! its a new object so it gets its own
mailing address automatically.
Unfortunately, you are receiving some of your neighbour's mail and none
of your own. Strangely enough, you notice that the address posted on
your front porch is not correct (it shows your neighbour's address!
What the hell?).
How do you prevent that situation? What if you have 10,000 of these
houses to get copied?