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;
}
};
Si tratta di un bug di VC++ 2012?È possibile decltype dichiarare un valore r?
I tipi non sono valori r o l-vales; i tipi sono * tipi *. La classificazione del valore-l/valore-r è per * espressioni *. –
Per riferimento, compila sotto gcc 4.6.3 con il flag C++ 0x. Penso che sia giusto, considerando che entrambi i tuoi loop sono identici. –
Il tipo per i in B :: operator == è dedotto come const int, sembra un bug VC. – Andrey