Class-Type Class Members

A class can have members that are of a class type or are pointers or references to a class type. Members that are of a class type must be of a class type that is previously declared . An incomplete class type can be used in a member declaration as long as the size of the class is not needed. For example , a member can be declared that is a pointer to an incomplete class type.

A class X cannot have a member that is of type X , but it can contain pointers to X, references to X, and static objects of X. Member functions of X can take arguments of type X and have a return type of X. For example:

class X
{
      X();
      X *xptr;
      X &xref;
      static X xcount;
      X xfunc(X);
};

The bodies of member functions are always processed after the definition of their class is complete. For this reason, the body of a member function can refer to the name of the class that owns it. even if this requires information about the class definition.

The language allows member functions to refer to any class member even if the member function definition appears before the declaration of that member in the class member list. For example,

class Y
{
public:
      int a;
      Y ();
private:
      int f() {return sizeof(Y);};
      void g(Y yobj);
      Y h(int a);
};

In this example, it is permitted for the inline function f() to make use of the size of class Y.



Incomplete Class Declarations
Member Functions
Inline Member Functions
Class Member Lists