Proper way to create unique_ptr that holds an allocated array

前端 未结 6 2003
天命终不由人
天命终不由人 2020-12-07 11:31

What is the proper way to create an unique_ptr that holds an array that is allocated on the free store? Visual studio 2013 supports this by default, but when I use gcc versi

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 11:40

    Probably something like the following?

    using namespace std;
    
    int size = get_size();
    int const init_value = 123;
    
    unique_ptr p = make_unique(size)
    fill(p.get(), p.get() + size, init_value);
    

提交回复
热议问题