its simple a constructor is called to make an object and a destructor is called to destroy an object.
your class...
Code:
class P1
{
public:
typedef unsigned long ULONG;
P1() : h(0),m(0),s(0) {} // constructor. syntax looks daunting
P1( ULONG H,ULONG M,ULONG S)
{
h = H;
m=( M > 59 )? 59 : M ;
s = (S > 59 ) ? 59:S;
}
P1( const P1& rhs ) : h(rhs.h),m(rhs.m),s(rhs.s) {}
~P1() {} // the do nothing destructor
private:
ULONG h, m, s;
};
Notice we have three constructors.
the first allows us to do this....
Its called a default constructor.
The next allows us to do this...
Code:
P1 myp1 (10,10,10);
constructing from ULONG,ULONG,ULONG
the last one is called the copy constructor. This constructs from another P1 object.
The destructor does othing in this example as there are no resources to be freed. Destructors get heavier use when you deal with dynamic memory.