Listing 5 (main1.cpp)

// main1.cpp
// a quick test of RefCntPtr

#define DEBUG

#include "anyclass.hpp"

void main (void)
 {
  RefCntPtr(anyClass) ptr1;
  
  // should evaluate to false,
  // not execute show
  if (ptr1)
     ptr1->show();
  
  ptr1 = new anyClass;
  if (!ptr1)
     cout << "new failed\n";
  
  ptr1->intVal = 17;
  ptr1->string =
   "I wanna go to Australia, too";
  
  // another access method
  (*ptr1).show();
  
  RefCntPtr(anyClass) ptr2 = ptr1;
  ptr2->show();
  
  ptr1 = 0;
  // this one is an error
  ptr1->show();
  
  ptr2->show();
  
  // previous anyClass will be deleted
  ptr2 = new anyClass;
  ptr2->intVal = 1234;
  ptr2->string =
   "Kansas? Why?";
  
  // ptr2 destructor will be called here,
  // at end of function, resulting
  // in call to anyClass destructor
 };
// End of File