Why does the compiler allow a function to return a value that is stored as a reference
Posted
by kern
on Stack Overflow
See other posts from Stack Overflow
or by kern
Published on 2010-04-12T18:54:36Z
Indexed on
2010/04/12
19:03 UTC
Read the original article
Hit count: 277
Can anybody explain why this code does not generate a compiler error?
class Foo
{
public:
int _x;
};
Foo getFoo()
{
Foo myfoo;
myfoo._x = 10;
return myfoo;
}
int _tmain()
{
// should this line of code not be a compiler error?
Foo& badfoo = getFoo();
return 0;
}
© Stack Overflow or respective owner