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,
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:
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.
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|