std::unique_ptr::operator[] - 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/>
<tbody> </tbody>
|
|
(dal C++11) | |
operator[] fornisce l'accesso a elementi di un array gestito da un unique_ptr.
Original:
operator[] provides access to elements of an array managed by a unique_ptr.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Il i parametro è necessario per essere un indice di array valido.
Original:
The parameter i is required to be a valid array index.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Parametri
| i | - | l'indice dell'elemento da restituire Original: the index of the element to be returned The text has been machine-translated via Google Translate. |
Valore di ritorno
Restituisce l'elemento in corrispondenza dell'indice i, vale a dire get()[i].
Original:
Returns the element at index i, i.e. get()[i].
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> #include <memory> int main() { const int size = 10; std::unique_ptr<int[]> fact(new int[size]); for (int i = 0; i < size; ++i) { fact[i] = (i == 0) ? 1 : i * fact[i-1]; } for (int i = 0; i < size; ++i) { std::cout << i << ": " << fact[i] << '\n'; } }
Output:
0: 1 1: 1 2: 2 3: 6 4: 24 5: 120 6: 720 7: 5040 8: 40320 9: 362880
Vedi anche
restituisce un puntatore all'oggetto gestito Original: returns a pointer to the managed object The text has been machine-translated via Google Translate. (metodo pubblico) [modifica] | |