A class declaration introduces the class name into the scope where
it 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 an
elaborated-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]