Is it a bug that Microsoft VS C++ compiler can Initialize a reference from a temporary object [duplicate]
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
精彩评论