Declaring Unsized Arrays in Member Lists (Microsoft Specific)

Unsized arrays can be declared in class member lists as the last data member if the program is not compiled with the ANSI-compatibility option (/Za). Because this is a Microsoft extension, using unsized arrays in this way can make your code less portable. To declare an unsized array, simply omit the first dimension. For example:

class Symbol

{

public:

int SymbolType;

char SymbolText[];

};

Restrictions

If a class contains an unsized array, it cannot be used as the base class for another class. In addition, a class containing an unsized array cannot be used to declare any member except the last member of another class.

The sizeof operator, when applied to a class containing an unsized array, returns the amount of storage required for all members except the unsized array. Implementors of classes that contain unsized arrays should provide alternate methods for obtaining the correct size of the class.

You cannot declare arrays of objects that have unsized array components. Also, performing pointer arithmetic on pointers to such objects generates an error message.