Typedef declaration
De 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. |
La declaración typedef proporciona una forma de crear un alias que se pueden utilizar en cualquier lugar, en lugar de un nombre de tipo (posiblemente compleja) .
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.
Contenido |
[editar] Sintaxis
typedef type_declaration;
|
|||||||||
[editar] Explicación
La declaración que sigue a la palabra clave typedef es lo contrario de una declaración de tipo normal (excepto que los especificadores de otro tipo, por ejemplo static, no se puede utilizar). Se podrá declarar uno o varios Indentifiers en la misma línea (por ejemplo, int y un puntero a int), podrá declarar matriz y tipos de funciones, punteros y referencias, tipos de clase, etc Cada identificador introducido en esta declaración se convierte en un typedef-nombre en lugar de un objeto que se convertiría si la palabra clave typedef fue removido .
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.
Los nombres typedef-son alias de tipos existentes, y no son declaraciones de nuevos tipos. Typedef no se puede utilizar para cambiar el significado de un nombre de tipo existente (incluyendo un nombre typedef-). Una vez declarado, un nombre typedef-sólo puede declararse para referirse a la misma vez. Nombres typedef sólo están en vigor en el ámbito en el que son visibles: las diferentes funciones o declaraciones de clase pueden definir tipos que se denominen con significado diferente .
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.
[editar] Palabras clave
[editar] Ejemplo
// 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; };
[editar] Ver también
alias de tipo proporcionar la misma funcionalidad que typedefs utilizando una sintaxis diferente, y son también aplicables a nombres de plantilla .
Original:
alias de tipo 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.