Namespace
Varianti

User-defined literals (dal C++11)

Da cppreference.com.
< cpp‎ | language

 
 
Linguaggio C + +
Temi generali
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.
Controllo del flusso
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.
Dichiarazioni esecuzione condizionale
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.
Iterazione dichiarazioni
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.
Vai dichiarazioni
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.
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dichiarazione di funzione
lambda funzione dichiarazione
funzione di modello
specificatore inline
eccezioni specifiche (deprecato)
noexcept specificatore (C++11)
Eccezioni
Original:
Exceptions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Spazi dei nomi
Original:
Namespaces
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Tipi
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 specificatori
Durata di stoccaggio specificatori
constexpr specificatore (C++11)
specificatore auto (C++11)
alignas specificatore (C++11)
Inizializzazione
Original:
Initialization
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Letterali
Original:
Literals
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
letterali booleani
nullptr (C++11)
definito dall'utente (C++11)
Espressioni
Original:
Expressions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rappresentazioni alternative
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.
Tipi
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
Tipo alias dichiarazione (C++11)
attributi (C++11)
Lancia
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversioni implicite
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
Fusione C-stile e funzionale
Occupazione della memoria
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.
Classi
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Specifiche per una classe di funzioni proprietà
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.
esplicito (C++11)
statico
Funzioni membro speciali
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.
Modelli
Original:
Templates
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
classe template
funzione di modello
modello di specializzazione
parametri confezioni (C++11)
Varie
Original:
Miscellaneous
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Montaggio in linea
 
C + 11 ha introdotto la possibilità di aggiungere suffissi personalizzati per letterali, al fine di fornire valori diversi.
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.
Suffisso letterale può essere sovraccaricato in modo molto simile agli operatori.
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.

[modifica] Sintassi

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 }

[modifica] Spiegazione

return -
Valore di ritorno
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 -
Dichiarazione sequenza specificatore, può contenere le parole chiave come constexpr o inline
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 -
Un valido C + + identificatore, preceduto da un carattere di sottolineatura. Identificatori senza sottolineatura sono riservati per uso futuro
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 -
Valore risultante da un letterale integrale
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 -
Valore risultante da una virgola letterale
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 -
Valore risultante da un carattere letterale
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 -
Stringa null-terminated, come analizzato dal compilatore, per i valori letterali interi e virgola mobile
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 e le dimensioni da una stringa letterale
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 -
Funzione del corpo
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.

[modifica] Esempi

// 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