Function template
Da 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. |
Índice |
[editar]Descrição
Os modelos permitem projeto função genérica de que o trabalho em vários tipos, sem a necessidade de reescrevê-lo várias vezes
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.
[editar]Sintaxe
[editar]Declaração
template< template_arguments> function_declaration | (1) | ||||||||
exporttemplate< template_arguments> function_declaration | (2) | (até C++11) | |||||||
# Declaração da função Template Erro de citação:
</ref>
de fecho em falta, para o elemento <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.
# Exportados declaração função de modelo. O corpo da função pode ser definida em um arquivo separado Erro de citação:
</ref>
de fecho em falta, para o elemento <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.
[editar]Argumentos
classidentifier | (1) | ||||||||
typenameidentifier | (2) | ||||||||
integral_typeidentifier | (3) | ||||||||
classidentifier= type_name | (4) | (desde C++11) | |||||||
typenameidentifier= type_name | (5) | (desde C++11) | |||||||
integral_typeidentifier= const_expr | (6) | (desde C++11) | |||||||
Dentro da função identifier pode ser usado como um 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.
Dentro da função identifier pode ser usado como uma constante
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.
Argumentos padrão
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.
[editar]Especialização
Esta seção está incompleta Motivo: partial specialization |
template<> retfunction_name< template_args> ( func_args) body | |||||||||
Especialização muda a implementação da função de modelo para os parâmetros do modelo específicos
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.
[editar]Chamar
function_name< template_args> ( func_args) | (1) | ||||||||
function_name( unambiguous_func_args) | (2) | ||||||||
Argumentos de modelo # explícitas, se func_args não combinam perfeitamente com os tipos como na declaração modelo (com o template_args dado) o elenco habitual irá ocorrer
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.
# Implícitas argumentos de modelo, deduzidos os argumentos da função. Nenhuma ambiguidade pode estar 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.
Esta seção está incompleta Motivo: better explanation/example |
[editar]Exemplo
Esta seção está incompleta |
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}
[editar]Consulte também
[editar]Notas
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.