智能指针分配动态数组

    auto ptr_arr = std::make_shared<int[]>();

    std::unique_ptr<int[]> up1(new int[10]());

    //C++14以后语法
    auto up2 = std::make_unique<A[]>(3);

    auto sp3(std::shared_ptr<A[]>(new A[3]));

   //#include <boost/make_shared.hpp>

    auto b_ptr_arr = boost::make_shared<A[]>(3);

结论,c++14之前,不支持make_unique,c++20之前不支持std::make_shared创建数组

猜你喜欢

转载自blog.csdn.net/qq_53332653/article/details/111954635