The declaration that follows the keyword typedef is otherwise a normal type declaration (except that other type specifiers, e.g. static, cannot be used). It may declare one or many indentifiers on the same line (e.g. int and a pointer to int), it may declare array and function types, pointers and references, class types, etc. Every identifier introduced in this declaration becomes a typedef-name rather than an object that it would become if the keyword typedef was removed.

The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions.

The typedef-names are aliases for existing types, and are not declarations of new types. Typedef cannot be used to change the meaning of an existing type name (including a typedef-name). Once declared, a typedef-name may only be redeclared to refer to the same type again. Typedef names are only in effect in the scope where they are visible: different functions or class declarations may define identically-named types with different meaning.

The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions.

// simple typedeftypedefunsignedlong ulong;// the following two objects have the same typeunsignedlong l1;
ulong l2;// more complicated typedeftypedefint int_t, *intp_t, (&fp)(int, ulong), arr_t[10];// the following two objects have the same typeint a1[10];
arr_t a2;// common C idiom to avoid having to write "struct S"typedefstruct{int a;int b;} S;// the following two objects have the same typestruct{int a;int b;} s1;
S s2;// error: conflicting type specifier// typedef static unsigned int uint;// std::add_const, like many other metafunctions, use member typedefstemplate<class T>struct add_const {typedefconst T type;};