#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(const 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";
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgRm9vCnsKcHJpdmF0ZToKCWludCBtX2RhdGE7CgkKcHVibGljOgoJRm9vKCkgOiBtX2RhdGEoNDIpCgl7CgkJc3RkOjpjb3V0IDw8ICJGb28gY29uc3RydWN0b3JcbiI7CQoJfQoJCglGb28oY29uc3QgRm9vJiBvdGhlcikKCXsKCQlzdGQ6OmNvdXQgPDwgIkZvbyBjb3B5IGNvbnN0cnVjdG9yXG4iOwoJCW1fZGF0YSA9IG90aGVyLm1fZGF0YTsKCX0KCQoJfkZvbygpCgl7CgkJc3RkOjpjb3V0IDw8ICJGb28gZGVzdHJ1Y3RvclxuIjsKCX0KfTsKCmNsYXNzIEJhcgp7CglGb28gbV9mb287CnB1YmxpYzoKCUJhcihjb25zdCBGb28mIGZvbykKCTogbV9mb28oZm9vKQoJewoJCXN0ZDo6Y291dCA8PCAiQmFyIGNvbnN0cnVjdG9yXG4iOwoJfQoJCgl+QmFyKCkKCXsKCQlzdGQ6OmNvdXQgPDwgIkJhciBkZXN0cnVjdG9yXG4iOwoJfQp9OwoKaW50IG1haW4oKQp7CglGb28gbXlGb287CglCYXIgYmFyKG15Rm9vKTsKCQoJc3RkOjpjb3V0IDw8ICIgOjogRW5kIG9mIHByb2dyYW0gc2NvcGUgOjogXG4iOwp9