J
Jim Langston
I remember there was a thread a while back that was talking about using the
return value of a function as a reference where I had thought the reference
would become invalidated because it was a temporary but it was stated that
it would not. This has come up in an irc channel but I can not find the
original thread, nor can I get any code to work.
Foo& Bar( int Val )
{
return Foo( Val );
}
Will not work, can not convert Foo to Foo&
Foo Bar( int Val )
{
return Foo( Val );
}
int main()
{
Foo& Inst = Bar( 10 );
}
Does not work, same thing, can not convert Foo to Foo&.
Foo& Bar(int Val )
{
Foo Temp( Val );
return Foo( Val );
}
int main()
{
Foo& Inst = Bar( 10 );
}
Does not work, checking the value of Val_ later shows garbage data
indicating the reference has become invalidated (as expected). Can anyone
remember the case where a temp value returned from a function can be used as
a reference and not invalidated immediately?
return value of a function as a reference where I had thought the reference
would become invalidated because it was a temporary but it was stated that
it would not. This has come up in an irc channel but I can not find the
original thread, nor can I get any code to work.
Foo& Bar( int Val )
{
return Foo( Val );
}
Will not work, can not convert Foo to Foo&
Foo Bar( int Val )
{
return Foo( Val );
}
int main()
{
Foo& Inst = Bar( 10 );
}
Does not work, same thing, can not convert Foo to Foo&.
Foo& Bar(int Val )
{
Foo Temp( Val );
return Foo( Val );
}
int main()
{
Foo& Inst = Bar( 10 );
}
Does not work, checking the value of Val_ later shows garbage data
indicating the reference has become invalidated (as expected). Can anyone
remember the case where a temp value returned from a function can be used as
a reference and not invalidated immediately?