decltype specifier
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. |
Überprüft den deklarierten Typ eines Unternehmens oder fragt den Rückgabetyp eines Ausdrucks .
Original:
Inspects the declared type of an entity or queries the return type of an expression.
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.
Inhaltsverzeichnis |
[Bearbeiten]Syntax
decltype ( entity) | (1) | (seit C++11) | |||||||
decltype ( expression) | (2) | (seit C++11) | |||||||
[Bearbeiten]Erklärung
1)
Wenn das Argument ist entweder die unparenthesised Namen eines Objekts / Funktion, oder ein Mitglied Zugang Ausdruck (
object.member
oder pointer->member
), dann die decltype gibt den deklarierten Typ des entity durch diesen Ausdruck angegeben .Original:
If the argument is either the unparenthesised name of an object/function, or is a member access expression (
object.member
or pointer->member
), then the decltype specifies the declared type of the entity specified by this expression.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.
2)
Wenn das Argument eine andere Ausdruck des Typs
T
, dannOriginal:
If the argument is any other expression of type
T
, thenThe 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.
a)
wenn die Value-Kategorie der expression ist xWert, dann die decltype gibt
T&&
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.
b)
wenn der Wert Kategorie expression ist lvalue, dann die decltype gibt
T&
Original:
if the value category of expression is lvalue, then the decltype specifies
T&
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.
c)
Andernfalls gibt decltype
T
Original:
otherwise, decltype specifies
T
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.
Beachten Sie, dass, wenn der Name eines Objekts parenthesised es ein L-Wert Ausdruck wird damit decltype(arg) und decltype((arg)) sind oft verschiedene Arten .
Original:
Note that if the name of an object is parenthesised, it becomes an lvalue expression, thus decltype(arg) and decltype((arg)) are often different types.
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.
decltype
ist nützlich bei der Deklaration von Typen, die nur schwer oder gar nicht zu erklären, unter Verwendung von Standard-Notation, wie Lambda-verwandte Typen oder Arten, die auf Template-Parameter abhängig sind .Original:
decltype
is useful when declaring types that are difficult or impossible to declare using standard notation, like lambda-related types or types that depend on 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]Keywords
[Bearbeiten]Beispiel
#include <iostream> struct A {double x;};const A* a = new A(); decltype( a->x ) x3;// type of x3 is double (declared type) decltype((a->x)) x4 = x3;// type of x4 is const double& (lvalue expression) template<class T, class U>auto add(T t, U u)-> decltype(t + u);// return type depends on template parameters int main(){int i =33; decltype(i) j = i*2; std::cout<<"i = "<< i <<", "<<"j = "<< j <<'\n'; auto f =[](int a, int b)->int{return a*b;}; decltype(f) f2{f};// the type of a lambda function is unique and unnamed i = f(2, 2); j = f2(3, 3); std::cout<<"i = "<< i <<", "<<"j = "<< j <<'\n';}
Output:
i = 33, j = 66 i = 4, j = 9
[Bearbeiten]Siehe auch
(C++11) | erhält die Art des Ausdrucks in unevaluierten Kontext Original: obtains the type of expression in unevaluated context The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (Funktions-Template) |