|
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) (责任编辑:) |
