Additional Class considerations.
  1. Destructor
    A special function like the constructor. It is called whenever an object is deallocated. It is the just the name of the class, but it is preceded by a ~.

  2. const
    This will create an object that cannot be modified. Any attempt to modify the object creates a syntax error. Furthermore, member functions must be declared const in order to access the const object. Member functions that modify an object will not be allowed to access a const object.

  3. this
    Every object has access to its own address though a pointer called this. The this pointer is used implicitly to reference data members and member functions of an object. The this pointer may also be used explicitly to enable constructs like nested function calls.

  4. friend
    A class may declare other classes or functions as friends. A friend may access the private members of a class.

  5. static data members
    Every object has its own copy of all of the data members. In certain cases only one copy of a data member should be used by every object. This is accomplished through static data members.

  6. Copy constructor
    When a constructor takes a pointer to the class object as input it is called a copy constructor and invoked whenever a copy of the object is instantiated. For example when an object to passed to a function a copy is requested.

  7. new and delete
    new and delete can be used on objects to create or destroy copies of objects on the dynamic heap.

  8. Composition.
    When a class uses object of another class this is called composition. In cases of composition it will be necessary for the class constructor to specify how constructors are called for its data members.

  9. Example of these considerations
    1. The main module
      //
      //
      #include "c2.h"
      #include "c2a.h"
      #include <iostream.h>
      #include <iomanip.h>
      
      void main()
      
      {
      	const Time noon(12,0);
      	Time a,b(12,30);
          
      
      	noon.display();
      
      	a.display();
      	b.display();
      
      
      	a.setHour(10);
      	a.display();
      
      	a.setMinute(24);
      	a.display();
      
      	a.setHour(14).setMinute(47);
      	a.display();
        
      	b.setHour(12).setMinute(57);
      	b.display();
      
      	Time c=a;
      	c.display();
      
      	backdoorset(a,17,78);
      	a.display();
      
      	Time *p;
      
      	p = new Time(4,30);
      	p->display();
      	delete p;
      
      
      	Course cplus("C++",5,30);
      
      	cplus.display();
      
      	cplus.reschedule(9,30);
      
      
      }
      
      
    2. Running the code
      Constructor --1
      Constructor --2
      Constructor --3
               FROM DISPLAY   1--12:00
               FROM DISPLAY   2--00:00
               FROM DISPLAY   3--12:30
               FROM DISPLAY   2--10:00
               FROM DISPLAY   2--10:24
               FROM DISPLAY   2--14:47
               FROM DISPLAY   3--12:57
      Copy constructor --4
               FROM DISPLAY   4--14:47
       In friend function for 2
               FROM DISPLAY   2--17:78
      Constructor --5
               FROM DISPLAY   5--04:30
      Called destructor   on 5
      Constructor --6
      course display C++       FROM DISPLAY   6--05:30
      course display C++       FROM DISPLAY   6--09:30
      Called destructor   on 6
      Called destructor   on 4
      Called destructor   on 3
      Called destructor   on 2
      Called destructor   on 1
      
    3. Header Module for Time c2.h
      //
      //
      //
      #ifndef c2h
      #define  c2h
      #include 
      
      class Time{
      
      friend void backdoorset(Time&, int, int);
      
      private:
      	int reference;
      	int hour;
      	int minute;
          static int count;
      
      	void getCount();
      
      public:
      
      	Time(int h=0, int m=0);
      	Time(Time&);
      	~Time();
      	void display(void)   const;
      	Time& setHour(int);
      	Time& setMinute(int);
      	
      	
      };
      #endif
      
    4. Implementation module for Time objects
      #include "c2.h"
      #include <iostream.h>
      #include <iomanip.h>
      
      int Time::count=0;
      
      //   CONSTRUCTOR
      Time::Time(int h, int m)
      {
      	 hour = h >=0 && h < 25 ? h : 0;
      	 minute = m >= 0 && m < 61 ? m : 0;
      	 count++;
      	 reference=count;
      	 cout << "Constructor --" << reference << endl;
      }
      
      // COPY CONSTRUCTOR
      Time::Time(Time& copy )
      {
      	
      	hour=copy.hour;
      	minute=copy.minute;
      	count++;
      	reference=count;
      	cout << "Copy constructor --" << reference << endl;
      }
      
      // DESTRUCTOR
      Time::~Time()
      {
      	cout  << "Called destructor   on " << reference << endl;
      }
      
      // DISPLAY MEMBER FUNCTION
      void Time::display() const
      {
      	cout << "\t FROM DISPLAY \t"
      		 << reference << "--"
      		 << setw(2) << setfill('0') << hour 
      		 << ":" 
               << setw(2) << setfill('0') << minute
      		 << endl;
      }
      
      // MEMBER FUNCTION
      Time& Time::setHour(int h)
      {
      	hour = h >= 0 && h < 25 ? h : 0;
      	return *this;
      }
      
      // MEMBER FUNCTION
      Time& Time::setMinute(int m)
      {
      	minute = m >= 0 && m < 61 ? m : 0;
           return *this;
      }
      
      
      
      // MEMBER FUNCTION
      void Time::getCount()
      {
      	cout << count << " Time objects" << endl;
      }
      
      
      //Friend function allowed privileges
      void backdoorset(Time& x, int h , int m)
      {
      	cout << " In friend function for " << x.reference << endl;
      	x.hour=h;
      	x.minute=m;
      }
      
    5. Header module for Composite class
      //
      // Composition
      //
      #ifndef c2ah
      #define c2ah
      #include "c2.h"
      #include <iostream.h>
      
      class Course {
      private :
      	char		name[20];
      	Time		when;
      
      public:
      	Course(char*,int,int);
      	void display() const;
      	void reschedule(int, int);
      
      };
      #endif
      
    6. Composite class member functions
      //
      //  cousre modules.
      //
      #include <string.h>
      #include "c2a.h"
      
      Course::Course(char* n, int h, int m) : when (h,m)
      {
        strcpy(name,n);
      }
      
      void Course::display() const
      {
      	cout << "course display " << name;
      	when.display();
      }
      void Course::reschedule(int h, int m)
      {
          when.setHour(h).setMinute(m);
          display();
      }