Constructors are called
every time you create an object, and
destructors are called every time you
destroy an object.
•Constructors and destructors do not have
return types nor can they return values.
•References and pointers cannot be used on
constructors and destructors because their
addresses cannot be taken.
•Constructors cannot be declared with the
keyword virtual.
•Constructors and destructors cannot be
declared static, const, or volatile.
•Unions cannot contain class objects that
have constructors or destructors.
Constructor Example
Employee::Employee() {
points = 10;
work = 10;
health = 10;
}
Destructor Example
The name of the destructor is the name of
the class, preceded by a tilde (~). Here's
an example of a destructor:
Employee::~Employee() {
points = 0;
work = 0;
health = 0;
}
|