#include using namespace std; // Definition for Class SL class SL { private: // Each object contains two values int *ptr; // Pointer to int int val; // Just an int public: // Member functions SL(); ~SL(); SL(const SL &); void Readin(); void Printout(); void Erase(); }; // Constructor for Class SL SL::SL() {ptr = 0; cout << "allocated SL " << this << endl; } SL::~SL() {cout << "deallocated SL " << this << endl; this->Erase();} // Copy Constructor for Class SL SL::SL(const SL & fr) {cout << "Copy Constructructor from SL " << &fr << " to SL " << this << endl; this->val = fr.val; this->ptr = 0; if (fr.ptr) {ptr = new int; *ptr = *(fr.ptr); } return; } void SL::Printout() // Printing out the contents of a SL { if (ptr == 0) {cout << "data " << " 0 value none int " << val << endl; return;} cout << "data " << ptr << " value " << *ptr << " int " << val << endl; return; } void SL::Readin() // Reading in the contents of a SL { cout << "Input one value" << endl; ptr = new int; cin >> *ptr >> val; } void SL::Erase() { delete(ptr); ptr=0; } int main() { cout << endl; SL l; //A30 l.Readin(); cout << "SL l" << " Located at " << &l << endl; l.Printout(); cout << endl; // A30 A08 4 3 SL m; // A20 m.Readin(); cout << "SL m" << " Located at " << &m<< endl; m.Printout(); cout << endl; // A20 A18 2 1 SL o = m; // A10 // There is a correct copy constructor so it works cout << "SL o" << " Located at " << &o<< endl; o.Printout(); cout << endl; // Copy A20 to A10 // A10 A28 2 1 l.Erase(); m.Erase(); // Ok to use the o list after this point cout << "SL l" << " Located at " << &l<< endl; l.Printout(); // A30 A0 --- 3 cout << "SL m" << " Located at " << &m<< endl; m.Printout(); // A20 A0 --- 1 cout << "SL o" << " Located at " << &o<< endl; o.Printout(); // A10 A28 2 1 cout << endl; return 0; }