Namespace
Varianti

this pointer

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
 
All'interno non statico funzione membro, contiene un puntatore all'oggetto classe da cui viene chiamata la funzione.
Original:
Inside non-static member function, holds a pointer to the class object from which the function was invoked.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Il tipo di puntatore è this cv T* const dove T è il nome della classe e cv si riferisce alla cv specificatori della funzione viene utilizzato il puntatore in Per esempio:
Original:
The type of this pointer is cv T* const where T is the class name and cv refers to the cv specificatori of the function the pointer is used in. For example:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Function signature Type of this
void T::foo()                T* const this;
void T::foo() const          const T* const this;
void T::foo() volatile       volatile T* const this;
void T::foo() const volatile const volatile T* const this;

[modifica] Esempio

class T
{
    int x;
 
    void foo()
    {
        this->x = 5; // this used explicitly
        x = 6; // same as this->x = 6;
    }
 
    void foo() const
    {
        this->x = 7; // Error: *this is constant
    }
 
    void foo ( int x )
    {
        // parameter x shadows the attribute with the same name
        this->x = x; // unqualified x refers to the parameter, but the attribute is still accessible using the this pointer 
    }
 
    T& operator= ( const T& b )
    {
        x = b.x;
        return *this; // this is often used when a reference to the current object is needed
    }
 
    void bar ( const T& b )
    {
        // two ways to call class operators using this 
        (*this) = b;
        this->operator= ( b );
    }
 
    void bar()
    {
       // methods can be called even when there's no object
       // the this pointer can be seen like an additional parameter implicitly passed
       if ( this == NULL )
          return;
    }
};
 
T* pointer = reinterpret_cast<T*>(123);
pointer->bar(); // bar is called with 123 (0x7B) as value for this