【发布时间】:2012-08-06 21:15:51
【问题描述】:
让我们考虑下面的代码sn-p
void Test()
{
int x = 0;
int& rx = x;
int* px = &x;
auto apx = px; // deduced type is int*
auto arx = rx; // deduced type is int
}
可以从指针类型中进行类比,期望arx 的推导类型是int&,但实际上它是int。
标准中的规则是什么?背后的原因是什么? 有时我会在这样的情况下被它抓住:
const BigClass& GetBigClass();
...
auto ref_bigclass = GetBigClass(); // unexpected copy is performed
【问题讨论】:
标签: c++ c++11 type-inference