Examples of Declaring Class Objects


/************************************************************************
*

In C++, unlike C, you do not need to precede declarations of class objects with the keywords union, struct, and class unless the name of the class is hidden. For example:

                                                                        *
************************************************************************/


struct Y { /* ... */ };
class X { /* ... */ };
void main ()
{
      int X;             // hides the class name X
      Y yobj;            // valid
      X xobj;            // error, class name X is hidden
      class X xobj;      // valid
}


/************************************************************************
*

The following example declares a reference, a pointer, and an array:

                                                                        *
************************************************************************/


class X { /* ... */ };
struct Y { /* ... */ };
union Z { /* ... */ };
void main()
{
      X xobj;
      X &xref = xobj;           // reference to class object of type X
      Y *yptr;                  // pointer to struct object of type Y
      Z zarray[10];             // array of 10 union objects of type Z
}