【发布时间】:2012-10-16 05:47:35
【问题描述】:
// 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 的错误吗?
【问题讨论】:
-
类型不是右值或左值;类型是类型。左值/右值分类适用于表达式。
-
作为参考,它在 gcc 4.6.3 下编译,带有 C++0x 标志。我认为这是正确的,考虑到你的两个循环是相同的。
-
B::operator== 中 i 的类型推导为 const int,看起来像一个 VC 错误。
标签: c++ visual-c++ c++11 visual-studio-2012 decltype