#include #include using namespace std; class SmallT{ public: SmallT(string n = "default"):name(n) { counter1++; myID = counter1; cout << "Building instance " << myID << " called " << name << endl << endl; } ~SmallT(){ cout << "Destroying instance " << myID << " which is called " << name << endl << endl; } static void HowMany() { cout << "\tThere have been " << counter1 << " instances fo SmallT created, "; counter2++; cout << "and you have asked " << counter2 << " times. " << endl << endl; } private: static inline int counter1{0}; static int counter2; int myID; string name; }; // only once and probably in the .cpp file int SmallT::counter2{0}; class BigT { public: BigT(int n): a("a"+to_string(n)), b("b"+to_string(n)) { cout << "In the constructor for BigT" << endl << endl; } ~BigT() { cout << "In the destructor for BigT" << endl << endl; } private: SmallT a, b; }; int main() { SmallT::HowMany(); SmallT first("The first one, standalone"); SmallT::HowMany(); SmallT second("The second one, standalone"); BigT big(1); SmallT::HowMany(); BigT bigger(2); { SmallT inside("The one inside of the block"); } SmallT last("The last smallT"); return 0; }