#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 two values" << endl; ptr = new int; cin >> *ptr >> val; } void SL::Erase() { delete(ptr); ptr=0; } int main() { cout << endl; SL l; // Ae0 l.Readin(); cout << "SL l" << " Located at " << &l << endl; l.Printout(); cout << endl; // Ae0 A08 4 3 SL m; // Ad0 m.Readin(); cout << "SL m" << " Located at " << &m<< endl; m.Printout(); cout << endl; // Ad0 A18 2 1 SL o(m); // Ac0 // Terrible copy because the default CC does not // copy the dynamic allocated memeory cout << "SL o" << " Located at " << &o<< endl; o.Printout(); cout << endl; // Ac0 A18 2 1 l.Erase(); m.Erase(); // One should not use the o list after this point // When we try to delete it it creates a seg fault cout << "SL l" << " Located at " << &l<< endl; l.Printout(); // Ae0 A0 -- 3 cout << "SL m" << " Located at " << &m<< endl; m.Printout(); // Ad0 A0 -- 1 cout << "SL o" << " Located at " << &o<< endl; o.Printout(); // Ac0 A18 ...2224 1 cout << endl; return 0; }