How to typedef std::unique_ptr with array

Question | Dec 30, 2016 | nextptr 

We want to manage a dynamically allocated int[] array with an std::unique_ptr.

enter image description here

Here is a sample use case code:

    // typedef  _____  unique_array_ptr_t; 
    int* iArr = new int[10];
    unique_array_ptr_t  uiPtr(iArr);
    //......more code...
    uiPtr[1] = 100;  

Note that:

  • The unique_array_ptr_t calls delete [] as it goes out of scope
  • We should be able to access the array elements through a subscript [] operator on unique_array_ptr_t

You have to choose the correct typedef definition of unique_array_ptr_t from given choices:

2015 nextptr