[class.name] (original) (raw)

A class declaration introduces the class name into the scope whereit is declared and hides any class, variable, function, or other declaration of that name in an enclosing scope.

If a class name is declared in a scope where a variable, function, or enumerator of the same name is also declared, then when both declarations are in scope, the class can be referred to only using anelaborated-type-specifier ([basic.lookup.elab]).

[Example 2: struct stat { }; stat gstat; int stat(struct stat*); void f() { struct stat* ps; stat(ps); } — _end example_]

A declaration consisting solely of class-key identifier; is either a redeclaration of the name in the current scope or a forward declaration of the identifier as a class name.

It introduces the class name into the current scope.

[Example 3: struct s { int a; };void g() { struct s; s* p; struct s { char* p; }; struct s; } — _end example_]

[Note 1:

Such declarations allow definition of classes that refer to each other.

[Example 4: class Vector;class Matrix { friend Vector operator*(const Matrix&, const Vector&);};class Vector { friend Vector operator*(const Matrix&, const Vector&);};

— _end example_]

— _end note_]