#include <iostream>
struct A
{
A( ) { }
A( const A& ) { std:: cout << "A::copy_constructor is called to make a copy\n " ; }
} ;
void foo( A object ) { std:: cout << "foo has recieved a copy of an object\n " ; }
A bar( ) { std:: cout << "bar - about to return an object by value\n " ; static A a ; return a ; }
int main( )
{
std:: cout << "about to call bar\n " ;
A object = bar( ) ;
std:: cout << "bar has returned\n " ;
std:: cout << "\n \n about to call foo\n " ;
foo( object) ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKc3RydWN0IEEKewogICAgQSgpIHt9CiAgICBBKCBjb25zdCBBJiApIHsgc3RkOjpjb3V0IDw8ICJBOjpjb3B5X2NvbnN0cnVjdG9yIGlzIGNhbGxlZCB0byBtYWtlIGEgY29weVxuIiA7IH0KfTsKCnZvaWQgZm9vKCBBIG9iamVjdCApIHsgc3RkOjpjb3V0IDw8ICJmb28gaGFzIHJlY2lldmVkIGEgY29weSBvZiBhbiBvYmplY3RcbiIgIDsgfQpBIGJhcigpIHsgc3RkOjpjb3V0IDw8ICJiYXIgLSBhYm91dCB0byByZXR1cm4gYW4gb2JqZWN0IGJ5IHZhbHVlXG4iIDsgc3RhdGljIEEgYSA7IHJldHVybiBhIDsgfQoKaW50IG1haW4oKQp7CiAgICBzdGQ6OmNvdXQgPDwgImFib3V0IHRvIGNhbGwgYmFyXG4iIDsKICAgIEEgb2JqZWN0ID0gYmFyKCkgOwogICAgc3RkOjpjb3V0IDw8ICJiYXIgaGFzIHJldHVybmVkXG4iIDsKCiAgICBzdGQ6OmNvdXQgPDwgIlxuXG5hYm91dCB0byBjYWxsIGZvb1xuIiA7CiAgICBmb28ob2JqZWN0KSA7Cn0K