谁能解释为什么这段代码不会产生编译错误?
class Foo
{
public:
int _x;
};
Foo getFoo()
{
Foo myfoo;
myfoo._x = 10;
return myfoo;
}
int _tmain()
{
// shouldn't this line of code be a compiler error?
Foo& badfoo = getFoo();
return 0;
}
最佳答案
您可能正在使用允许将其作为扩展的 VC++。
main.cpp:18: warning C4239: nonstandard extension used :
'initializing' : conversion from 'Foo' to 'Foo &'
关于c++ - 为什么编译器允许函数返回一个存储为引用的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2624556/