Operatori in C e C++: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Riga 163:
 
=== Operatori bit a bit ===
Tutti gli operatori bit a bit (o di manipolazione dei bit) esistono insia [[C e(linguaggio di programmazione)|C]] che [[C++]] e possono essere sovraccaricati insoltanto C++nel linguaggio inventato da [[Bjarne Stroustrup]].
{| class="wikitable" style="width:100%"
|+
! colspan="2" rowspan="2" |Operator name
! rowspan="2" |SyntaxNome dell'operatore
! colspanrowspan="2" |Prototype examplesSintassi
! colspan="2" |Esempi di implementazione in C++
|-
!Come membro di una classe
!As member of K
!Fuori dalla classe
!Outside class definitions
|-
!Complemento a uno (inversione di tutti i bit)
| class="table-rh" colspan="2" {{rh}} width="23%" |[[Bitwise operation#NOT|Bitwise NOT]]
| align="center" width="11%" |<code>'''~'''a</code><br /><br />
| width="25%" |{{cpp|<code>R K::operator ~();}}</code>
| width="25%" |{{cpp|<code>R operator ~(K a);}}</code>
|-
!AND bit a bit
| class="table-rh" colspan="2" {{rh}} |[[Bitwise operation#AND|Bitwise AND]]
| style="text-align:center;" |<code>a '''&''' b</code>
|{{cpp|<code>R K::operator &(S b);}}</code>
|{{cpp|<code>R operator &(K a, S b);}}</code>
|-
!OR inclusivo bit a bit
| class="table-rh" colspan="2" {{rh}} |[[Bitwise operation#OR|Bitwise OR]]
| style="text-align:center;" |<code>a '''<nowiki>|</nowiki>''' b</code>
|{{cpp|<code><nowiki>R K::operator {{!}}|(S b);|lang=cpp}}</nowiki></code>
|{{cpp|<code><nowiki>R operator {{!}}|(K a, S b);|lang=cpp}}</nowiki></code>
|-
!OR esclusivo bit a bit (OR exclusive, XOR)
| class="table-rh" colspan="2" {{rh}} |[[Bitwise operation#XOR|Bitwise XOR]]
| style="text-align:center;" |<code>a '''^''' b</code>
|{{cpp|<code>R K::operator ^(S b);}}</code>
|{{cpp|<code>R operator ^(K a, S b);}}</code>
|-
| class="table-rh" colspan="2" {{rh}} |[[Bitwise shift|Bitwise left shift]]<ref name="bitshift" group="lower-alpha" />
| style="text-align:center;" |<code>a '''<<''' b</code>
|{{cpp|R K::operator <<(S b);}}
|{{cpp|R operator <<(K a, S b);}}
|-
!Spostamento di tutti i bit verso sinistra
| class="table-rh" colspan="2" {{rh}} |[[Bitwise shift|Bitwise right shift]]<ref name="bitshift" group="lower-alpha" />{{Refn|name="rightbitshift"|group="lower-alpha"|According to the C99 standard, the right shift of a negative number is implementation defined. Most implementations, e.g., the GCC,<ref name="Integers">{{Citation | contribution = Integers implementation | url = //gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Integers-implementation.html#Integers-implementation | title = GCC 4.3.3 | publisher = GNU}}.</ref> use an [[arithmetic shift]] (i.e., sign extension), but a [[logical shift]] is possible.}}
| style="text-align:center;" |<code>a '''>><<''' b</code>
|{{cpp|<code>R K::operator >><<(S b);}}</code>
|{{cpp|<code>R operator >><<(K a, S b);}}</code>
|-
!Spostamento di tutti i bit verso destra
| style="text-align:center;" |<code>a '''<<>>''' b</code>
|{{cpp|<code>R K::operator <<>>(S b);}}</code>
|{{cpp|<code>R operator <<>>(K a, S b);}}</code>
|}