After
typedefint MILES, *KLICKSP;
the constructions
MILES distance;
extern KLICKSP metricp;
are all correct declarations; the type of distance is
int and that of metricp is “pointer to int”.
In a given non-class scope, a typedef specifier can be used to
redeclare the name of any type declared in that scope to refer to the
type to which it already refers.
[Example 3: typedefstruct s {/* ... */} s;
typedefint I;
typedefint I;
typedef I I;
— end example]
In a given class scope, a typedef specifier can be used to
redeclare any class-name declared in that scope that is not
also a typedef-name to refer to the type to which it already
refers.
[Example 4: struct S {typedefstruct A {} A; // OKtypedefstruct B B; // OKtypedef A A; // error};
— end example]
If a typedef specifier is used to redeclare in a given scope an
entity that can be referenced using an elaborated-type-specifier,
the entity can continue to be referenced by an
elaborated-type-specifier or as an enumeration or class name
in an enumeration or class definition respectively.
[Example 5: struct S;
typedefstruct S S;
int main(){struct S* p; // OK}struct S {}; // OK — end example]
Similarly, in a given scope, a class or enumeration shall not be
declared with the same name as a typedef-name that is
declared in that scope and refers to a type other than the class or
enumeration itself.
[Example 7: typedefint complex;
class complex {/* ... */}; // error: redefinition — end example]
If the typedef declaration defines an unnamed class or enumeration, the first
typedef-name declared by the declaration to be that type
is used to denote the type for linkage purposes only ([basic.link]).
A typedef declaration involving a lambda-expression
does not itself define the associated closure type,
and so the closure type is not given a name for linkage purposes.
— end note]
[Example 9: typedefstruct{}*ps, S; // S is the class name for linkage purposestypedefdecltype([]{}) C; // the closure type has no name for linkage purposes — end example]