◐ Shell
clean mode source ↗

Typedef declaration - cppreference.com

Da cppreference.com.

Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.

La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui.

Click here for the English version of this page

<metanoindex/>

La dichiarazione typedef fornisce un modo per creare un alias che possono essere utilizzati ovunque al posto di una (possibilmente complessa) nome del tipo.

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.

Sintassi

typedef type_declaration;

Spiegazione

La dichiarazione che segue la parola chiave typedef è comunque una dichiarazione di tipo normale (tranne che gli identificatori di altro tipo, ad esempio static, non può essere utilizzato). Si può dichiarare una o più indentifiers sulla stessa linea (ad esempio int e un puntatore a int), può dichiarare array e tipi di funzione, i puntatori e riferimenti, tipi di classe, ecc Ogni identificatore introdotto in questa dichiarazione diventa un nome-typedef piuttosto di un oggetto che sarebbe diventato se il typedef parola chiave è stata rimossa.

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.

I nomi sono typedef-alias per i tipi esistenti, e non sono dichiarazioni di nuovi tipi. Typedef non può essere utilizzata per modificare il significato di un nome del tipo esistente (tra cui un nome-typedef). Una volta dichiarato, un nome-typedef può essere dichiarato nuovamente far riferimento allo stesso tipo di nuovo. I nomi typedef hanno effetto solo nel campo di applicazione in cui sono visibili: diverse funzioni o le dichiarazioni della classe possono definire tipi di nome identico con significato diverso.

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.

Parole chiave

typedef

Esempio

// 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;
};

Vedi anche

Tipo di alias forniscono la stessa funzionalità typedef utilizzando una sintassi diversa, e sono applicabili anche ai nomi dei modelli.

Original:

Tipo di alias 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.