
../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 templateinline 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;
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)