Empty Classes

You can declare empty classes, but objects of such types still have nonzero size. The following example illustrates this:

#include <iostream.h>

class NoMembers
{
};

void main()
{
    NoMembers n;  // Object of type NoMembers.

    cout << "The size of an object of empty class is: "
         << sizeof n << endl;
}

This is the output of the preceding program:

The size of an object of empty class is: 1.

The memory allocated for such objects is of nonzero size; therefore, the objects have different addresses. Having different addresses makes it possible to compare pointers to objects for identity. Also, in arrays, each member array must have a distinct address.

Microsoft Specific

An empty base class typically contributes zero bytes to the size of a derived class.

END Microsoft Specific