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(10);
   cout << object_1.getNumber() << "\n";
   delete &object_1;
   Object object_2(13);
   cout << object_1.getNumber() << "\n";
}