Local type names (C++ only)

Local type names follow the same scope rules as other names. Type names defined within a class declaration have class scope and cannot be used outside their class without qualification.

If you use a class name, typedef name, or a constant name that is used in a type name, in a class declaration, you cannot redefine that name after it is used in the class declaration.

For example:

int main ()
{
      typedef double db;
      struct st
      {
            db x;
            typedef int db; // error
            db y;
      };
}

The following declarations are valid:

typedef float T;
class s {
      typedef int T;
      void f(const T);
};

Here, function f() takes an argument of type s::T. However, the following declarations, where the order of the members of s has been reversed, cause an error:

typedef float T;
class s {
      void f(const T);
      typedef int T;
};

In a class declaration, you cannot redefine a name that is not a class name, or a typedef name to a class name or typedef name once you have used that name in the class declaration.

Related information



[ Top of Page | Previous Page | Next Page | Contents | Index ]