why must you provide the keyword const in operator overloads

Posted by numerical25 on Stack Overflow See other posts from Stack Overflow or by numerical25
Published on 2010-06-01T13:09:53Z Indexed on 2010/06/01 13:13 UTC
Read the original article Hit count: 268

Just curious on why a param has to be a const in operation overloading

CVector& CVector::operator= (const CVector& param)
{
  x=param.x;
  y=param.y;
  return *this;
}

couldn't you have easily done something like this ??

CVector& CVector::operator= (CVector& param) //no const
{
  x=param.x;
  y=param.y;
  return *this;
}

Isn't when something becomes a const, it is unchangeable for the remainder of the applications life ?? How does this differ in operation overloading ???

© Stack Overflow or respective owner

Related posts about c++

Related posts about c