【发布时间】:2016-06-09 08:12:59
【问题描述】:
我有如下程序:
struct A{ int i; };
int main()
{
const int i = 0;
auto ai = i;
ai = 2; // OK
const A buf[2];
for(auto& a : buf)
{
a.i = 1; // error!
}
std::cout << buf[0].i << buf[1].i << std::endl;
}
第一个auto ai = i;没有问题,好像auto没有检索到c/v限定符,因为ai可以修改
但是for循环编译失败--error: assignment of member A::i in read-only object
我知道auto 不会检索& 功能,
我的问题是:auto 是否像我的情况一样检索 c/v 限定符?
我的测试程序似乎给出了矛盾的提示。
【问题讨论】: