Saturday, June 10, 2017

Deep Classes Proper Design

/*This code was written by A. El-Gadi of Tripoli University for educational purposes. The code is a model answer to a Spring-2017 2nd exam question. For any questions use the comment section below.*/

#include <iostream>

using namespace std;

class AA{public: int d,e;};

class BB{public: int f,g;
    AA *a;
    BB(){a=new AA();}
    BB(const BB& b){a=new AA(*b.a);}
    ~BB(){delete a;}
    BB& operator=(BB b){ f=b.f; g=b.g; *a=*b.a; return *this;}
};

class CC{public: int h,i;
    BB *b;
    CC(){b=new BB();}
    CC(const CC& c){b=new BB(*c.b);}
    ~CC(){delete b;}
    CC& operator=(CC c){ h=c.h; i=c.i; *b=*c.b; return *this;}
    };

No comments:

Post a Comment