#include #include using namespace std; // you are allowed to do this, but it is meh . // Reusable code is one of the main points of OOP // And placing a class definition in a main is definately not reusable // But who would want to resue this silly class anyway. // We will do this for demo purposes. class FooT { public: FooT() { cout << "You built me without a name " << endl; name = "default"; } FooT(string n) { name = n; cout << "Creating the FooT " << name << endl; } ~FooT(void) { cout << "Destroying the FooT " << name << endl; } string Name() { return name; } private: string name; }; class BarT { public: BarT(string n) { cout << "Creating the BarT " << name << endl; name = n; data = new FooT(n+" (a member of BarT: " + name + ")"); } ~BarT() { cout << "Deleting the BarT " << name << endl; //delete data; } string Name() { return name; } private: FooT * data; string name; }; class LisaT { public: LisaT(string n): data("From a LisaT " + n) { cout << "Creating the LisaT " << name << endl; name = n; } ~LisaT() { cout << "Deleting the LisaT " << name << endl; } string Name() { return name; } private: FooT data; string name; }; int main() { cout << "Entering main " << endl; FooT bad; cout << "Declaring a single, static FooT: foo1 " << endl; FooT foo1("foo1"); cout << endl << endl; cout << "Declaring a static array of three FooT (A,B,C) " << endl; FooT fooList[]{FooT("A"),FooT("B"),FooT("C")}; cout << endl << endl; cout << "Declaring a first dynamic array of three FooT(D,E,F) " << endl; FooT * secondList = new FooT[3]{FooT("D"),FooT("E"),FooT("F")}; cout << endl << endl; FooT * inList = new FooT[5]; cout << "Declaring a LisaT Lisa1, which has a FooT static " << endl; LisaT lisa1("Lisa1"); cout << endl << endl; cout << "Declaring a BarT, bart1, which has a FooT dynamic " << endl; BarT bart1("bart1"); cout << endl << endl; cout << "Declaring a second dynamic array of BarT(BA, BB) " << endl; BarT * thirdList = new BarT[3]{BarT("D"),BarT("E"),BarT("F")}; cout << "Everything was created, now time to get rid of it " << endl; cout << endl << endl; cout << "First delete the first dynamic array" << endl; delete [] secondList; cout << endl << endl; cout << "Next delete the second dynamic array" << endl; delete [] thirdList; cout << endl << endl; cout << "exiting main" << endl; return 0; }