Unlike structures, classes support inheritance. For example:
This example illustrates one major reason for using a class: a class can be extended by inheritance, whereas a structure is not extensible. The previous example defines
DateTime to extend the
TimeOfDay class with a date.
If you are puzzled by the comment about the year 1753, search the Web for "1752 date change". The intricacies of calendars for various countries prior to that year can keep you occupied for months...
Classes only support single inheritance. The following is illegal:
A derived class also cannot redefine a data member of its base class: