Q:

Why copy constructor argument should be const in C++?

0

Why copy constructor argument should be const in C++?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

There are some important reasons to use const in the copy constructor.

  • const keyword avoids accidental changes.
  • You would like to be able to create a copy of the const objects. But if you’re not passing your argument with a const qualifier, then you can’t create copies of const objects.
  • You couldn’t create copies from temporary reference, because temporary objects are rvalue, and can’t be bound to reference to non-const.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Interview Questions For Experienced

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Can one constructor of a class call another constr... >>
<< Why copy constructor take the parameter as a refer...