Function template
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. |
Indice |
[modifica] Descrizione
Modelli consentono disegno generico funzione che opera su vari tipi, senza la necessità di riscrivere più volte
Original:
Templates allow generic function design that work on various types, without the need of rewriting it multiple times
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.
[modifica] Sintassi
[modifica] Dichiarazione
template < template_arguments > function_declaration
|
(1) | ||||||||
export template < template_arguments > function_declaration
|
(2) | (fino al c++11) | |||||||
# Modello dichiarazione di funzione Errore nella funzione Cite:
</ref>
di chiusura mancante per il marcatore <ref>
Original:
{{{2}}}
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.
# Esportati funzione dichiarazione modello. Il corpo della funzione può essere definito in un file separato Errore nella funzione Cite:
</ref>
di chiusura mancante per il marcatore <ref>
Original:
{{{2}}}
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.
[modifica] Argomenti
class identifier | (1) | ||||||||
typename identifier | (2) | ||||||||
integral_type identifier | (3) | ||||||||
class identifier = type_name
|
(4) | (dal C++11) | |||||||
typename identifier = type_name
|
(5) | (dal C++11) | |||||||
integral_type identifier = const_expr
|
(6) | (dal C++11) | |||||||
All'interno della funzione identifier può essere usata come tipo
3) Original:
Inside the function identifier can be used as a type
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.
All'interno della funzione identifier può essere usato come una costante
4-6) Original:
Inside the function identifier can be used as a constant
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.
Predefiniti argomenti
Original:
Default arguments
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.
[modifica] Specializzazione
This section is incomplete Reason: partial specialization |
template <> ret function_name < template_args > ( func_args ) body
|
|||||||||
Specializzazione cambia l'implementazione della funzione di modello per modello di parametri specifici
Original:
Specialization changes the implementation of the template function for specific template parameters
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.
[modifica] Chiama
function_name < template_args > ( func_args )
|
(1) | ||||||||
function_name ( unambiguous_func_args )
|
(2) | ||||||||
Argomenti di modello # espliciti, se func_args non corrispondono perfettamente con i tipi come nel modello di dichiarazione (con la template_args dato) il casting di consueto si verificherà
Original:
# Explicit template arguments, if func_args don't match perfectly with the types as in the template declaration (with the given template_args) the usual casting will occur
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.
Argomenti di modello # impliciti, desumibili dagli argomenti della funzione. Nessuna ambiguità può essere presente
Original:
# Implicit template arguments, deduced from the function arguments. No ambiguity can be present
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.
This section is incomplete Reason: better explanation/example |
[modifica] Esempio
This section is incomplete |
template<typename T> struct S { template<typename U> void foo(){} }; template<typename T> void bar() { S<T>s; s.foo<T>(); // error: < parsed as less than operator s.template foo<T>(); // OK }
[modifica] Vedere anche
[modifica] Note
Original:
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.