9
// Compiled by Visual Studio 2012
struct A
{
bool operator ==(const A& other) const
{
for (decltype(this->n) i = 0; i < n; ++i) // OK
{}
return true;
}
protected:
size_t n;
};
struct B : public A
{
bool operator ==(const B& other) const
{
for (decltype(this->n) i = 0; i < n; ++i) // error C2105: '++' needs l-value
{}
return true;
}
};
이것은 VC++ 2012의 버그입니까?decltype에서 r 값을 선언 할 수 있습니까?
유형은 r 값 또는 l 값이 아닙니다. 유형은 * 유형 *입니다. l 값/r 값 분류는 * 표현식 *에 대한 것입니다. –
참고로 gcc 4.6.3에서 C++ 0x 플래그로 컴파일됩니다. 두 루프가 동일하다는 점을 감안할 때 이것이 옳다고 생각합니다. –
B :: operator ==의 i에 대한 유형은 const int로 추론되며 VC 버그처럼 보입니다. – Andrey