class Cat
{
public:
Cat() :itsAge(0),itsWeight(0){}
Cat(int age, int weight) :itsAge(age), itsWeight(weight){}
int GetAge()const{ return itsAge; }
int GetWeight(){ return itsWeight; }
void operator+(const Cat &);
friend Cat operator+(const Cat &, const Cat &);
private:
int itsAge;
int itsWeight;
Cat operator+(const Cat & lhs, const Cat & rhs)
Cat temp;
int totalAge = lhs.GetAge() + rhs.GetAge();
int totalweight = lhs.GetWeight() + rhs.GetWeight();
}
디버그를 할때에 노란색친 두 부분에 대해서 아래와 같은 에러가 나오네요
error C2662: 'int Cat::GetAge(void)' : cannot convert 'this' pointer from 'const Cat' to 'Cat &'
1> Conversion loses qualifiers
operator+에서 두 매개변수에 '&'를 빼서 참조자가 아니게 해도 결과는 똑같구요
'아무래도 상수형 객체인 lhs와 rhs가 GetWeight()를 호출할려고 할때
GetWeight는 비상수형 멤버 함수가 아니기 때문에 호출할수가 없다.
즉, 클래스의 상수형 객체는 상수형 멤버 함수만 호출할수있다.'
로 해석해야 되는것 같은데... 맞나요??
책을 아무리 뒤져봐도 이런 상황은 안나오네요 ㅠㅠ