Function template
Aus 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. |
Inhaltsverzeichnis |
[Bearbeiten] Beschreibung
Vorlagen können generische Funktion Design, dass die Arbeit auf verschiedene Arten, ohne die Notwendigkeit von Umschreiben es mehrere Male
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.
[Bearbeiten] Syntax
[Bearbeiten] Erklärung
template < template_arguments > function_declaration
|
(1) | ||||||||
export template < template_arguments > function_declaration
|
(2) | (bis C + +11) | |||||||
# Template Funktion Erklärung Referenzfehler: Für ein
<ref>
-Tag fehlt ein schließendes </ref>
-Tag.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.
# Exportierte Template-Funktion Erklärung. Die Funktion Körper kann in einer separaten Datei definiert werden Referenzfehler: Für ein
<ref>
-Tag fehlt ein schließendes </ref>
-Tag.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.
[Bearbeiten] Argumente
class identifier | (1) | ||||||||
typename identifier | (2) | ||||||||
integral_type identifier | (3) | ||||||||
class identifier = type_name
|
(4) | (seit C++11) | |||||||
typename identifier = type_name
|
(5) | (seit C++11) | |||||||
integral_type identifier = const_expr
|
(6) | (seit C++11) | |||||||
Innerhalb der Funktion identifier kann als eine Art verwendet werden
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.
Innerhalb der Funktion identifier kann als Konstante eingesetzt werden
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.
Default-Argumente
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.
[Bearbeiten] Spezialisierung
This section is incomplete Reason: partial specialization |
template <> ret function_name < template_args > ( func_args ) body
|
|||||||||
Spezialisierung ändert die Umsetzung der Template-Funktion für bestimmte Template-Parameter
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.
[Bearbeiten] Rufen
function_name < template_args > ( func_args )
|
(1) | ||||||||
function_name ( unambiguous_func_args )
|
(2) | ||||||||
# Explizite Template-Argumente, wenn func_args nicht perfekt überein mit den Typen wie in der Vorlage Erklärung (mit dem angegebenen template_args) die übliche Casting auftreten
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.
# Implicit Template-Argumente, von den Funktionsargumente abgeleitet. Keine Mehrdeutigkeit vorhanden sein können
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 |
[Bearbeiten] Beispiel
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 }
[Bearbeiten] Siehe auch
[Bearbeiten] Notes
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.