可能的重复: typedef 和 const 指针的容器
为什么代码会发出错误?
int main() { //test code typedef int& Ref_to_int; const Ref_to_int ref = 10; }
错误是:
错误:从“int”类型的临时对象初始化“int&”类型的非常量引用无效
我读过关于延长临时文件的生命周期的帖子,其中说临时文件可以绑定到对 const 的引用。那为什么我的代码没有被编译?
c++ reference constants temporary
c++ ×1
constants ×1
reference ×1
temporary ×1