Problems with shared_ptr wrapping a dynamic array

后端 未结 4 1473
遇见更好的自我
遇见更好的自我 2021-01-13 02:08

I wanted to replace some raw pointers in my class with a std::shared_ptr so that I don\'t have to worry when I create copies of that class. But the raw pointers

4条回答
  •  梦谈多话
    2021-01-13 02:34

    If you specified the deleter then you don't use T[] in the template argument. Just change T[] to T:

    template  shared_ptr make_shared_array(size_t size)
    {
      return shared_ptr(new T[size], default_delete());
    }
    
    struct Foo
    {
      shared_ptr field;
    };
    

提交回复
热议问题