#include <iostream>
class Foo
{
private :
int m_data;
public :
Foo( ) : m_data( 42 )
{
std:: cout << "Foo constructor\n " ;
}
Foo( const Foo& other)
{
std:: cout << "Foo copy constructor\n " ;
m_data = other.m_data ;
}
~Foo( )
{
std:: cout << "Foo destructor\n " ;
}
} ;
class Bar
{
Foo m_foo;
public :
Bar( Foo foo)
: m_foo( foo)
{
std:: cout << "Bar constructor\n " ;
}
~Bar( )
{
std:: cout << "Bar destructor\n " ;
}
} ;
int main( )
{
Foo myFoo;
Bar bar( myFoo) ;
std:: cout << " :: End of program scope :: \n " ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgRm9vCnsKcHJpdmF0ZToKCWludCBtX2RhdGE7CgkKcHVibGljOgoJRm9vKCkgOiBtX2RhdGEoNDIpCgl7CgkJc3RkOjpjb3V0IDw8ICJGb28gY29uc3RydWN0b3JcbiI7CQoJfQoJCglGb28oY29uc3QgRm9vJiBvdGhlcikKCXsKCQlzdGQ6OmNvdXQgPDwgIkZvbyBjb3B5IGNvbnN0cnVjdG9yXG4iOwoJCW1fZGF0YSA9IG90aGVyLm1fZGF0YTsKCX0KCQoJfkZvbygpCgl7CgkJc3RkOjpjb3V0IDw8ICJGb28gZGVzdHJ1Y3RvclxuIjsKCX0KfTsKCmNsYXNzIEJhcgp7CglGb28gbV9mb287CnB1YmxpYzoKCUJhcihGb28gZm9vKQoJOiBtX2Zvbyhmb28pCgl7CgkJc3RkOjpjb3V0IDw8ICJCYXIgY29uc3RydWN0b3JcbiI7Cgl9CgkKCX5CYXIoKQoJewoJCXN0ZDo6Y291dCA8PCAiQmFyIGRlc3RydWN0b3JcbiI7Cgl9Cn07CgppbnQgbWFpbigpCnsKCUZvbyBteUZvbzsKCUJhciBiYXIobXlGb28pOwoJCglzdGQ6OmNvdXQgPDwgIiA6OiBFbmQgb2YgcHJvZ3JhbSBzY29wZSA6OiBcbiI7Cn0=