Namensräume
Varianten
Aktionen

User-defined literals (seit C++11)

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.
boolean Literale
nullptr (C++11)
benutzerdefiniert (C++11)
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
 
C + 11 wurde die Möglichkeit eingeführt, um benutzerdefinierte Suffixe Literale hinzufügen, um unterschiedliche Werte liefern .
Original:
C++11 introduced the ability to add custom suffixes to literals in order to provide different values.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Literal nachgestellte kann in einer Weise, ähnlich Betreiber überlastet werden .
Original:
Literal suffixed can be overloaded in a way very similar to operators.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Syntax

return decl operator"" name ( unsigned long long n ) { body }
return decl operator"" name ( long double d ) { body }
return decl operator"" name ( char c ) { body }
return decl operator"" name ( const char* str, size_t sz ) { body }
return decl operator"" name ( const char* cstr ) { body }

[Bearbeiten] Erklärung

return -
Rückgabewert
Original:
Return value
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decl -
Erklärung specifier Sequenz können Keywords als constexpr oder inline enthalten
Original:
Declaration specifier sequence, can contain keywords as constexpr or inline
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
name -
Eine gültige C + +-Kennung, die mit einem Unterstrich vorangestellt. Identifiers ohne Unterstrich sind reserviert für zukünftige Nutzung
Original:
A valid C++ identifier, prefixed with an underscore. Identifiers without underscore are reserved for future use
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n -
Wert, der sich aus einer integralen Literal
Original:
Value resulting from an integral literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
d -
Wert, der sich aus einer Fließkomma-Literal
Original:
Value resulting from a floating-point literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
c -
Wert, der sich aus einer Zeichenliteral
Original:
Value resulting from a character literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cstr -
Null-terminierter String durch den Compiler analysiert, für Integer-und Fließkomma-Literale
Original:
Null-terminated string as parsed by the compiler, for integer and floating point literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
str/sz -
Buffer und Größe aus einem Zeichenfolgenliteral
Original:
Buffer and size from a string literal
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
body -
Funktion Körper
Original:
Function body
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[Bearbeiten] Beispiele

// used as conversion
inline constexpr long double operator"" _deg ( long double deg )
{
    return deg*3.141592/180;
}
...
double x = 90.0_deg; // x = 1.570796


// used with custom type
struct mytype
{
    ...
    mytype ( unsigned long long );
};
mytype operator"" _mytype ( unsigned long long n )
{
    return mytype(n);
}
...
mytype x = 123_mytype;


// used for side-effects
void operator"" _print ( const char* str )
{
    std::cout << str;
}
...
0x123ABC_print;

Output:

0x123ABC