Vector(const Vector& other) // Copy constructor
{
x = other.x;
y = other.y;
为什么参数是 const?
最佳答案
你得到的答案提到确保 ctor 不能改变被复制的内容——他们是对的,把 const 放在那里确实有这种效果。
然而,更重要的是临时对象不能绑定(bind)到非常量引用。复制 ctor 必须引用 const 对象才能复制临时对象。
关于c++ - 为什么复制构造函数参数是 const?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1602058/