Namensräume
Varianten
Aktionen

Function template

Aus cppreference.com
< cpp‎ | language

 
 
Sprache C++
Allgemeine Themen
Original:
General topics
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Flusskontrolle
Original:
Flow control
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Bedingte Ausführung Aussagen
Original:
Conditional execution statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Iterationsanweisungen
Original:
Iteration statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Gehe Aussagen
Original:
Jump statements
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Funktion Erklärung
Lambda-Funktion Erklärung
Funktions-Template
inline-Spezifizierer
Exception-Spezifikationen (veraltet)
noexcept Spezifizierer (C++11)
Ausnahmen
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Namespaces
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype specifier (C++11)
Specifiers
Original:
Specifiers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cv Planer
Lagerdauer Planer
constexpr Spezifizierer (C++11)
auto Spezifizierer (C++11)
alignas Spezifizierer (C++11)
Initialisierung
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literale
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Expressions
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
alternative Darstellungen
Utilities
Original:
Utilities
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Types
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
typedef declaration
Typ Aliasdeklaration (C++11)
Attribute (C++11)
Wirft
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
impliziten Konvertierungen
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-Stil und funktionale Besetzung
Speicherzuweisung
Original:
Memory allocation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Class-spezifische Funktion Eigenschaften
Original:
Class-specific function properties
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
explizit (C++11)
statisch
Besondere Member-Funktionen
Original:
Special member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Templates
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Klassen-Template
Funktions-Template
Template-Spezialisierung
Parameter Packs (C++11)
Verschiedenes
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Inline Montage
 

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.

[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.
# 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.

[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)
1-2)
Innerhalb der Funktion identifier kann als eine Art verwendet werden
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.
3)
Innerhalb der Funktion identifier kann als Konstante eingesetzt werden
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.
4-6)
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.

[Bearbeiten] Spezialisierung

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.

[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.
# 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.

[Bearbeiten] Beispiel

[edit]
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.