织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

How can I use make

时间:2026-02-11 21:14来源: 作者:admin 点击: 0 次
First, std::make_unique()<Obj>(tmp) is incorrect syntax, it should be std::make_unique<Obj>(tmp) instead. Second, std::make_unique() does

First, std::make_unique()<Obj>(tmp) is incorrect syntax, it should be std::make_unique<Obj>(tmp) instead.

Second, std::make_unique() does not exist in C++11, it was added in C++14 (unlike std::make_shared(), which does exist in C++11).

If you look at the cppreference doc for std::make_unique(), it shows a possible implementation that (with minor tweaks) can be applied to C++11 code. If your code doesn't need to worry about std::unique<T[]> support for arrays, then the simplest implementation would look like this:

template<class T, class... Args> std::unique_ptr<T> make_unique(Args&&... args) { return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); }

Then you can use (without the std:: prefix):

make_unique<Obj>(tmp)

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2026-02-11 23:02 最后登录:2026-02-11 23:02
栏目列表
推荐内容