20-CS-122-001 Computer Science II Spring 2012
Craziness: Deletion of Objects

Virtual functions, classes, inheritance, lists, queues, stacks, applications

Prev      Next      Lectures      Source

#include <iostream>
using namespace std;

class Object {
   int number;
   
 public:
   Object (int n) { number = n; }
   int getNumber () { return number; }
};

int main () {
   Object *object_1 = new Object(10);
   cout << object_1->getNumber() << "\n";
   delete object_1; object_1 = NULL;
   cout << object_1->getNumber() << "\n";
   Object *object_2 = new Object(13);
   cout << object_1->getNumber() << "\n";
}