开发者

Is it a bug that Microsoft VS C++ compiler can Initialize a reference from a temporary object [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Binding temporary to a lvalue reference

With VS2008 C++ compiler, the codes are compiled without compile error.

class A{};

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

I believe the C++ standard, both C++2003 and coming C++0x, disallow it. And I also get a compile time error with gcc compi开发者_运维技巧ler.

So what I want to know is, is this a known bug for VS compiler to allow initializing reference from a temporary object.

Or is it a feature extension of VS compiler? If yes, what's life cycle of the temporary object?


It is the extension.This link explains it. What if we take out the const

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜