단순히 + 연산자를 오버로드하려고하고 있는데이 컴파일러 경고가 표시됩니다.C++ 컴파일러 경고 - 지역 변수 반환
reference to local variable 'tmp' returned
다음은 오버로드 코드입니다.
const Int& Int::operator+(const Int& p) const
{
Int tmp = value + p.value;
return tmp;
}
다음은 클래스
class Int{
int value;
public:
Int() {} // default constructor
Int(int v) : value(v) {}
Int& operator=(const Int&);
const Int& operator+(const Int&) const;
};
입니다.