【问题标题】:Is it a bug that Microsoft VS C++ compiler can Initialize a reference from a temporary object [duplicate]Microsoft VS C ++编译器可以从临时对象初始化引用是否是一个错误[重复]
【发布时间】:2011-09-23 23:12:59
【问题描述】:

可能重复:
Binding temporary to a lvalue reference

使用VS2008 C++编译器,编译代码没有编译错误。

class A{};

int main(){
    A& a_ref = A(); 
    return 0;
}

我相信 C++ 标准,包括 C++2003 和即将到来的 C++0x,都不允许它。而且我还收到 gcc 编译器的编译时错误。

所以我想知道的是,这是 VS 编译器允许从临时对象初始化引用的已知错误。

还是 VS 编译器的功能扩展?如果是,临时对象的生命周期是什么?

【问题讨论】:

    标签: c++ visual-c++ reference temporary


    【解决方案1】:

    它是扩展名。这个链接解释了它。 What if we take out the const

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-24
      • 2011-09-02
      • 2011-05-26
      • 2012-05-30
      • 1970-01-01
      • 2011-03-06
      相关资源
      最近更新 更多