Original Post
Say I have a data class, nothing fancy (i.e. no dynamic memory nor inheritance) and I want to return an object of that type in a non-related function (say another member function).
class Foo
{
public:
Foo::Foo(int); // no default ctor
};
class Goo
{
Foo getFoo();
};
Foo Goo::getFoo()
{
return Foo(5);
}
Now my question is: does the anonymous Foo object I created in getFoo() get returned? Does anybody out there really know the rules about anonymous objects?
Is the compiler-provided (shallow) copy constructor invoked, passing the object back by value? (I expect p-b-v is the only way to go...)
I realize anonymous objects have "expression-scope"; does that mean it exists until the constructor finishes, or when getFoo's "return" finishes?
Thanks ppl
class Foo
{
public:
Foo::Foo(int); // no default ctor
};
class Goo
{
Foo getFoo();
};
Foo Goo::getFoo()
{
return Foo(5);
}
Now my question is: does the anonymous Foo object I created in getFoo() get returned? Does anybody out there really know the rules about anonymous objects?
Is the compiler-provided (shallow) copy constructor invoked, passing the object back by value? (I expect p-b-v is the only way to go...)
I realize anonymous objects have "expression-scope"; does that mean it exists until the constructor finishes, or when getFoo's "return" finishes?
Thanks ppl