Now consider how the class declaration differs from a structure declaration:
class Date
{
public:
Date( int mn, int dy, int yr ); // Constructor
void display(); // Function to print date
~Date(); // Destructor
private:
int month, day, year; // Private data members
};
Like a structure declaration, it declares three data members: the integers month, day, and year. However, the class declaration differs from a structure declaration in several ways:
It has the keywords public and private.
It declares functions, like display.
It includes the constructor Date and the destructor ~Date.
Let's examine these differences one by one.