smart pointers and arrays

前端 未结 2 407
盖世英雄少女心
盖世英雄少女心 2020-11-27 14:56

How do smart pointers handle arrays? For example,

void function(void)
{
    std::unique_ptr my_array(new int[5]);
}

When m

2条回答
  •  执笔经年
    2020-11-27 15:38

    It will call delete[] and hence the entire array will be reclaimed but I believe you need to indicate that you are using an array form of unique_ptrby:

    std::unique_ptr my_array(new int[5]);
    

    This is called as Partial Specialization of the unique_ptr.

提交回复
热议问题