operators - cppreference.com
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
L'overload degli operatori
Sintassi
type operator op ( params ) ;
|
|||||||||
Spiegazione
<tipo> è / sono il tipo (s) delle variabili.
Original:
<type> is/are the type(s) of the variables.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.<op> è l'operatore particolare (ad esempio
+,+=,<<,>>,&&,||,%, ecc).Original:
<op> is the particular operator (e.g.
+,+=,<<,>>,&&,||,%, etc.).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.<params> è / sono il nome (s) i parametri necessari (dipende dal gestore).
Original:
<params> is/are the name(s) of the required parameters (depends on the operator).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Restrizioni
Non è possibile creare nuovi operatori come
**o&|.Original:
You cannot create new operators such as
**or&|.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.Non tutti gli operatori possono essere sottoposti a overload
Original:
Not all operators can be overloaded
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.Alcuni operatori possono essere sottoposti a overload come membri non statici della classe
Original:
Some operators can only be overloaded as non-static class members
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.Corto circuito di valutazione non funziona con operatori in overload
Original:
Short-circuit evaluation doesn't work with overloaded operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Operatore Chiamate
Operatori di overload può essere chiamato con la notazione infissa solito
Original:
Overloaded operators can be called using the usual infix notation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
o di una funzione-notazione
Original:
or a function-like notation
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Esempio
#include <iostream> using namespace std; class Fraction{ private: int numerator, denominator; public: Fraction(int n, int d): numerator(n), denominator(d) {} // Note that the keyword operator combined with an actual // operator is used as the function name friend ostream& operator<<(ostream&, Fraction&); }; ostream& operator<<(ostream& out, Fraction& f){ out << f.numerator << '/' << f.denominator; return out; } int main(){ Fraction f1(3, 8); Fraction f2(1, 2); cout << f1 << endl; cout << 3 << ' ' << f2 << endl; return 0; }
Output:
Vedere anche
| Common operators | ||||||
|---|---|---|---|---|---|---|
| assegnazione | incrementNJdecrement | aritmetica | logico | confronto | memberNJaccess | altra |
|
|
|
|
|
|
|
|
| Special operators | ||||||
|
static_cast
converte un tipo a un altro Original: static_cast converts one type to another compatible type The text has been machine-translated via Google Translate. dynamic_cast
converte classe virtuale di base per class Original: dynamic_cast converts virtual base class to derived class The text has been machine-translated via Google Translate. const_cast
converte il tipo di tipo compatibile con diversi cv qualifiers Original: const_cast converts type to compatible type with different cv qualifiers The text has been machine-translated via Google Translate. reinterpret_cast
converte tipo type Original: reinterpret_cast converts type to incompatible type The text has been machine-translated via Google Translate. new
alloca memory Original: new allocates memory The text has been machine-translated via Google Translate. delete
dealloca memory Original: delete deallocates memory The text has been machine-translated via Google Translate. sizeof
interroga la dimensione di un type Original: sizeof queries the size of a type The text has been machine-translated via Google Translate. sizeof...
interroga le dimensioni di un parametro confezione (dal C++11) Original: sizeof... queries the size of a parametro confezione (dal C++11) The text has been machine-translated via Google Translate. typeid
interroga le informazioni sul tipo di una type Original: typeid queries the type information of a type The text has been machine-translated via Google Translate. noexcept
controlla se un'espressione può lanciare una (dal C++11) Original: noexcept checks if an expression can throw an exception (dal C++11) The text has been machine-translated via Google Translate. alignof
query requisiti di allineamento di un (dal C++11) tipo Original: alignof queries alignment requirements of a type (dal C++11) The text has been machine-translated via Google Translate. | ||||||