코드를 Ubuntu 4.4.1 g ++ 컴파일러로 전송했습니다. 아래에 operator ++ (int)
을 오버로드하는 동안 (T*)
에 대해 오류가 발생하지만 (T*&)
에는 정상적으로 작동합니다. 이전 버전 (linux-64에서는 정확한 버전을 기억하지 못함)에서는 (T*)
도 정상적으로 작동했습니다.오류 : 연산자가 오버로드되는 동안 lvalue가 필요합니다. ++/- etc
이유가 있다면 ?
template<typename T>
struct Wrap
{
void *p; // Actually 'p' comes from a non-template base class
Wrap<T>& operator ++()
{
((T*)p) ++; // throws error; if changed to (T*&) then ok!
return *this;
}
// ...
};
int main()
{
Wrap<int> c;
++c; // calling prefix increment
}
'operator ++ (int)'를 의미 했습니까? – GManNickG