//deepcopy.cpp //where have all the children gone #include #include using namespace std; #define GOODCOPY //global ofstream out("familyout.txt", ios::app); class family { private: int momsAge; int dadsAge; int numKids; int* theKidsAges; public: family(const int m, const int d, const int n); #ifdef GOODCOPY family(const family & f); //copy constructor #endif ~family(); void display() const; //const here says won't change calling object void changeAnAge(int kidnumber,int age); #ifdef GOODCOPY const family & operator=(const family & right); #endif }; family::family(int m, int d, int n) { momsAge=m; dadsAge=d; numKids=n; theKidsAges=0; if (numKids!=0) { theKidsAges=new int[numKids]; int i; for (i=0;i> theKidsAges[i]; out << theKidsAges[i] << endl; //echo } //end for } //end if } #ifdef GOODCOPY family::family(const family & f) { momsAge=f.momsAge; dadsAge=f.dadsAge; numKids=f.numKids; theKidsAges=0; //below is the part the compiler wouldn't do if (numKids!=0) { theKidsAges=new int[numKids]; for (int i=0; i=1 && kidnumber<=numKids) theKidsAges[kidnumber-1]=age; } #ifdef GOODCOPY const family & family::operator=(const family & right) { out << "In operator=\n"; //get rid of old family if (numKids!=0) delete [] theKidsAges; theKidsAges=0; //copy new family momsAge=right.momsAge; dadsAge=right.dadsAge; numKids=right.numKids; if (numKids!=0) { theKidsAges=new int[numKids]; int i; for (i=0;i