1

I know much things about copy constructor. How is it called and why '&' and 'const' is needed. When it is created by default and what kind of copies it generate etc.

Recently, I was having a discussion with one of my juniors about it and he asked: "Why do we use const in copy constructor parameters". I told him two-fold answer:

One, We should use const wherever possible. Two, We should use it so that compiler deals with temporary objects and do not let them die.

But his smile seems to suggest me that there is more about "Why do we use const". More about this is here.

I browsed through the internet and I was getting only above two reasons. Interested to know what are the other reasons for using 'const'.

Hemant Bhargava
  • 3,251
  • 4
  • 24
  • 45

0 Answers0