Elaborated type specifiers are used to declare user-defined types. These can be either class- or enumerated-types.
Syntax
elaborated-type-specifier :
class-key class-name
class-key identifier
enum enum-name
class-key :
class
struct
union
If identifier is specified, it is taken to be a class name. For example:
class Window;
This statement declares the Window
identifier as a class name. This syntax is used for forward declaration of classes. For more information about class names, see Class Names in Chapter 8.
If a name is declared using the union keyword, it must also be defined using the union keyword. Names that are defined using the class keyword can be declared using the struct keyword (and vice versa). Therefore, the following code samples are legal:
// Legal example 1
struct A; // Forward declaration of A.
class A // Define A.
{
public:
int i;
};
// Legal example 2
class A; // Forward declaration of A.
struct A // Define A.
{
private:
int i;
};
// Legal example 3
union A; // Forward declaration of A.
union A // Define A.
{
int i;
char ch[2];
};
These examples, however, are illegal:
// Illegal example 1
union A; // Forward declaration of A.
struct A // Define A.
{
int i;
};
// Illegal example 2
union A; // Forward declaration of A.
class A // Define A.
{
public:
int i;
};
// Illegal example 3
struct A; // Forward declaration of A.
union A // Define A.
{
int i;
char ch[2];
};