Typedef declaration
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
typedef声明提供了一种方法,可以在任何地方使用的地方(可能是复杂的)类型名称创建一个别名.
Original:
The typedef declaration provides a way to create an alias that can be used anywhere in place of a (possibly complex) type name.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 语法
typedef type_declaration;
|
|||||||||
[编辑] 解释
声明如下关键字typedef否则一个正常的类型声明,惟其他类型说明符,例如static,不能使用。在同一行上(如int和指针为int),它可能会声明一个或许多indentifiers中,它可能会声明数组和成为一个typedef名称,而每个标识符在这个声明引入的函数类型,指针和引用,类类型,等等。比一个对象,它会成为如果关键字typedef除去.
Original:
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.
You can help to correct and verify the translation. Click here for instructions.
typedef定义的名称是为现有类型的别名,而不是新型的声明。 typedef不能用来改变现有的类型名称(包括一个typedef名称)的意义。声明后,一个typedef名字可能会被重新声明,指相同类型的。 typedef名称是唯一的有效的范围内,他们是可见:不同的函数或类声明可以定义相同名称的类型与不同的含义.....
Original:
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.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 关键字
[编辑] 为例
// simple typedef typedef unsigned long ulong; // the following two objects have the same type unsigned long l1; ulong l2; // more complicated typedef typedef int int_t, *intp_t, (&fp)(int, ulong), arr_t[10]; // the following two objects have the same type int a1[10]; arr_t a2; // common C idiom to avoid having to write "struct S" typedef struct {int a; int b;} S; // the following two objects have the same type struct {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 typedefs template< class T> struct add_const { typedef const T type; };
[编辑] 另请参阅
类型的别名类型定义使用不同的语法,提供相同的功能,也适用于模板的名称.
Original:
类型的别名 provide the same functionality as typedefs using a different syntax, and are also applicable to template names.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.