‘make

‘make,第1张

‘make
../UniqueStrTest/main.cpp: In function ‘int main(int, char**)’:
../UniqueStrTest/main.cpp:35:25: error: ‘make_unique’ is not a member of ‘std’
           auto p = std::make_unique(); // p 是占有 D 的 unique_ptr
                         ^~~~~~~~~~~

make_unique从c++14开始,c++11不支持,但是可以自己实现make_unique

  /// std::make_unique for single objects
  template
    inline typename _MakeUniq<_Tp>::__single_object
    make_unique(_Args&&... __args)
    { return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...)); }

  /// std::make_unique for arrays of unknown bound
  template
    inline typename _MakeUniq<_Tp>::__array
    make_unique(size_t __num)
    { return unique_ptr<_Tp>(new remove_extent_t<_Tp>[__num]()); }

  /// Disable std::make_unique for arrays of known bound
  template
    inline typename _MakeUniq<_Tp>::__invalid_type
    make_unique(_Args&&...) = delete;

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4951296.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-13
下一篇2022-11-13

发表评论

登录后才能评论

评论列表(0条)

    保存