Partager via


Elaborated Type Specifiers

Elaborated type specifiers are used to declare user-defined types. These can be either class- or enumerated-types.

class identifier
struct identifier
union identifier
enum identifier

Remarks

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.

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:

Example

// elaborated_type_specifiers1.cpp
struct A;   // Forward declaration of A.

class A   // Define A.
{
public:
   int i;
};

int main()
{
}

// elaborated_type_specifiers2.cpp
class A;   // Forward declaration of A

struct A
{
private:
    int i;
};

int main()
{
}

// elaborated_type_specifiers3.cpp
union A;   // Forward declaration of A

union A
{
   int  i;
   char ch[2];
};

int main()
{
}

The following examples, however, are illegal:

// elaborated_type_specifiers4.cpp
union A;   // Forward declaration of A.

struct A
{   // C2011
   int i;
};

// elaborated_type_specifiers5.cpp
union A;   // Forward declaration of A.

class A
{   // C2011
public:
   int i;
};

// elaborated_type_specifiers6.cpp
struct A;   // Forward declaration of A.

union A
{   // C2011
   int  i;
   char ch[2];
};

See Also

Reference

C++ Type Specifiers