#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(); 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();} 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; } #include "listNode.h" int main() { cout << endl; SL* l; // A08 l = new SL; l->Readin(); cout << "SL* l" << " Located at " << l << endl; l->Printout(); cout << endl; // A08 A18 4 3 SL* m; // A28 m = new SL; m->Readin(); cout << "SL* m" << " Located at " << m<< endl; m->Printout(); cout << endl; // A28 A38 2 1 SL* o= new SL(*m); // A48 // Terrible copy because CC is the default one // and it does not copy dynamically allocated memory cout << "SL* o" << " Located at " << o<< endl; o->Printout(); cout << endl; // A48 A38 2 1 l->Erase(); m->Erase(); // One should not use the o list after this point cout << "SL* l" << " Located at " << l<< endl; l->Printout(); // A08 A0 -- 3 cout << "SL* m" << " Located at " << m<< endl; m->Printout(); // A28 A0 -- 1 cout << "SL* o" << " Located at " << o<< endl; o->Printout(); // A48 A38 ...3648 1 delete l; delete m; delete o; cout << endl; return 0; }