#include<iostream>
#include<map>
#include<vector>
#include<string>
using namespace std;
class ObjTrace {
public:
string tag;
int n;
ObjTrace(string tag, int n) {
this->tag = tag;
this->n = n;
cout<<tag<<"("<<n<<"): i live"<<endl;
}
ObjTrace(const ObjTrace& other) {
this->tag = other.tag;
this->n = other.n+1;
cout<<tag<<"("<<n<<"): a new me"<<endl;
}
~ObjTrace() {
cout<<tag<<"("<<n<<"): i die"<<endl;
}
};
class Bar:ObjTrace{
public:
Bar(string tag):ObjTrace(tag, 0) {
}
};
class Foo:ObjTrace{
public:
vector<Bar> stuff;
Foo(string tag):ObjTrace(tag, 0) {
}
};
int main() {
map<string, Foo> foo;
foo.insert(make_pair("a", Foo("a")));
vector<Bar> *vec = &foo.find("a")->second.stuff;
vec->push_back(Bar("b"));
vec->push_back(Bar("c"));
cout<<"cleanup."<<endl;
foo.clear();
cout<<"end."<<endl;
}