Why is the copy-constructor argument const?

前端 未结 8 2117
时光说笑
时光说笑 2020-11-29 00:30
 Vector(const Vector& other) // Copy constructor 
 {
    x = other.x;
    y = other.y;

Why is the argument a const?

8条回答
  •  旧巷少年郎
    2020-11-29 01:11

    when we try to copy one object into another using copy constructor,we need to maintain the original copy of original object (which we are copying) so while passing object we make it constant and we pass it as a by reference.

提交回复
热议问题