1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
When a tt(unique_ptr) is used to store arrays the dereferencing operator makes
little sense but with arrays tt(unique_ptr) objects benefit from index
operators. The distinction between a single object tt(unique_ptr) and a
tt(unique_ptr) referring to a dynamically allocated array of objects is
realized through a template specialization.
With dynamically allocated arrays the following syntax is available:
itemization(
it() the index (tt([])) notation is used to specify that the smart
pointer controls a dynamically allocated em(array). Example:
verb(unique_ptr<int[]> intArr(new int[3]);)
it() the index operator can be used to access the array's
elements. Example:
verb(intArr[2] = intArr[0];)
)
In these cases the smart pointer's destructors call
tt(delete[]) rather than tt(delete).
|