1 2 3 4 5 6 7 8 9 10 11 12
|
The tt(shared_ptr) class can also be used to handle dynamically allocated
arrays of objects. To use it on arrays simply use the square brackets when
specifying the tt(shared_ptr's) type. Here is an example:
verbinclude(//code examples/sharedarray.cc)
When the tt(shared_ptr) itself is initialized with an array of pointers, then
a em(deleter) must be used to delete the memory the pointers point at. In that
case the deleter is responsible for returning the memory to the common pool,
using tt(delete[]) when eventually deleting the array of pointers:
verbinclude(//SHAREDARRAY examples/sharedarray2.cc)
|