In the following scenario:
struct Foo
{
// ...
operator Bar() {... } // implicit cast to Bar
}
Foo GetFoo() { ... }
void CallMeBar(Bar x) { ... }
// ...
CallMeBar( GetFoo() );
[edit] fixed the cast operator, d'oh[/edit]
GetFoo
returns a temporary object of Type Foo. Does this object survive until after CallMe returns? What does the standard say?
I understand that if CallMe
would accept Foo, the temporary object would not be destroyed until after CallMe
returns. I am not sure, however, fi the implicit cast changes this, and only the temporary Bar
is guaranteed to survive.
A typical case would be Foo = CString, Bar = char *, i.e. Bar referencing data held by (and freed by) Foo.