Table of Contents
Previous Section Next Section

Structures

A structure is created using the keyword struct. In C++, a structure also defines a class. The only difference between class and struct is that, by default, all members of a structure are public. To make a member private, you must use the private keyword. The general form of a structure declaration is like this:

struct struct-name : inheritance-list {
 // public members by default
protected:
 // private members that can be inherited
private:
 // private members
} object-list;

In C, several restrictions apply to structures. First, they may contain only data members; member functions are not allowed. C structures do not support inheritance. Also, all members are public and the keywords public, protected, and private are not allowed.


Table of Contents
Previous Section Next Section