RAD Studio |  |

Class Name Scope
See Also
Collapse All

The scope of a class name is local. There are some special requirements if the class name appears more than once in the same scope. Class name scope starts at the point of declaration and ends with the enclosing block. A class name hides any class, object, enumerator, or function with the same name in the enclosing scope. If a class name is declared in a scope containing the declaration of an object, function, or enumerator of the same name, the class can be referred to only by using the elaborated type specifier. This means that the class key, class, struct, or union, must be used with the class name. For example,

Copy Code

    struct S { ... };
    int S(struct S *Sptr);
    void func(void) {
       S t;         // ILLEGAL declaration: no class key and function S in scope
       struct S s;  // OK: elaborated with class key
       S(&s);       // OK: this is a function call
    }

C++ also allows a forward class declaration:

Copy Code

    class X;  // no members, yet!

Forward declarations permit certain references to class name X (usually references to pointers to class objects) before the class has been fully defined. See Structure member declarations for more information. Of course, you must make a complete class declaration with members before you can define and use objects of that class.

See also the syntax for forward declarations of VCL classes.

See Also

C++ Classes

Class Types

Class Objects

Class Member List

Member Functions

The Keyword This

Static Members

Inline Functions

Member Scope

Nested Types

Member Access Control

Base And Derived Class Access

Virtual Base Classes

Friends Of Classes

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!