Proper way to create unique_ptr that holds an allocated array

前端 未结 6 2021
天命终不由人
天命终不由人 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:43

    Use the array version :

    auto testData = std::unique_ptr{ new unsigned char[16000] };
    

    Or with c++14, a better form ( VS2013 already has it ):

    auto testData = std::make_unique( 16000 );
    

提交回复
热议问题