【发布时间】:2011-08-29 14:23:18
【问题描述】:
为什么代码会发出错误?
int main()
{
//test code
typedef int& Ref_to_int;
const Ref_to_int ref = 10;
}
错误是:
错误:从“int”类型的临时变量中“int&”类型的非常量引用的初始化无效
我阅读了prolonging the lifetime of temporaries 上的帖子,其中说临时对象可以绑定到对 const 的引用。那为什么我的代码没有被编译?
【问题讨论】:
标签: c++ reference constants temporary