Namespace
Varianti

operators

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

Indice

[modifica] L'overload degli operatori

[modifica] Sintassi

type operator op ( params ) ;

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

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

[modifica] 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.
a+b
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.
operator+(a,b)

[modifica] 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:

3/8
3 1/2

[modifica] Vedere anche

Common operators
assegnazione incrementNJdecrement aritmetica logico confronto memberNJaccess altra

a = b
a = rvalue
a += b
a -= b
a *= b
a /= b
a %= b
a &= b
a |= b
a ^= b
a <<= b
a >>= b

++a
--a
a++
a--

+a
-a
a + b
a - b
a * b
a / b
a % b
~a
a & b
a | b
a ^ b
a << b
a >> b

!a
a && b
a || b

a == b
a != b
a < b
a > b
a <= b
a >= b

a[b]
*a
&a
a->b
a.b
a->*b
a.*b

a(...)
a, b
(type) a
? :

Special operators
static_cast converte un tipo a un altro
tipo compatibile
Original:
static_cast converts one type to another compatible type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
dynamic_cast converte classe virtuale di base per class
derivato
Original:
dynamic_cast converts virtual base class to derived class
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
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.
You can help to correct and verify the translation. Click here for instructions.
reinterpret_cast converte tipo type
incompatibile
Original:
reinterpret_cast converts type to incompatible type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
new alloca memory
Original:
new allocates memory
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
delete dealloca memory
Original:
delete deallocates memory
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
sizeof interroga la dimensione di un type
Original:
sizeof queries the size of a type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
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.
You can help to correct and verify the translation. Click here for instructions.
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.
You can help to correct and verify the translation. Click here for instructions.
noexcept controlla se un'espressione può lanciare una (dal C++11)
un'eccezione
Original:
noexcept checks if an expression can throw an exception (dal C++11)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
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.
You can help to correct and verify the translation. Click here for instructions.