首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >error::make_unique不是‘std’的成员

error::make_unique不是‘std’的成员
EN

Stack Overflow用户
提问于 2014-07-07 11:13:21
回答 6查看 139.2K关注 0票数 115

我试图编译下面的线程池程序张贴在代码审查,以测试它。

https://codereview.stackexchange.com/questions/55100/platform-independant-thread-pool-v4

但我会发现错误

代码语言:javascript
复制
threadpool.hpp: In member function ‘std::future<decltype (task((forward<Args>)(args)...))> threadpool::enqueue_task(Func&&, Args&& ...)’:
threadpool.hpp:94:28: error: ‘make_unique’ was not declared in this scope
     auto package_ptr = make_unique<task_package_impl<R, decltype(bound_task)>>  (std::move(bound_task), std::move(promise));
                        ^
threadpool.hpp:94:81: error: expected primary-expression before ‘>’ token
     auto package_ptr = make_unique<task_package_impl<R, decltype(bound_task)>>(std::move(bound_task), std::move(promise));
                                                                             ^
main.cpp: In function ‘int main()’:
main.cpp:9:17: error: ‘make_unique’ is not a member of ‘std’
 auto ptr1 = std::make_unique<unsigned>();
             ^
main.cpp:9:34: error: expected primary-expression before ‘unsigned’
 auto ptr1 = std::make_unique<unsigned>();
                              ^
main.cpp:14:17: error: ‘make_unique’ is not a member of ‘std’
 auto ptr2 = std::make_unique<unsigned>();
             ^
main.cpp:14:34: error: expected primary-expression before ‘unsigned’
 auto ptr2 = std::make_unique<unsigned>();
EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2014-07-07 11:16:50

make_unique是一个即将推出的C++14功能,因此您的编译器可能无法使用它,即使它符合C++11。

不过,您可以轻松地滚动您自己的实现:

代码语言:javascript
复制
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
    return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

(被投票为make_unique的FYI,C++14。这包括用于覆盖数组的附加函数,但总体思路仍然相同。)

票数 175
EN

Stack Overflow用户

发布于 2016-02-23 04:55:04

如果有最新的编译器,则可以在构建设置中更改以下内容:

代码语言:javascript
复制
 C++ Language Dialect    C++14[-std=c++14]

这对我有用。

票数 16
EN

Stack Overflow用户

发布于 2018-09-30 03:44:05

1.gcc版>= 5

2.CXXFLAGS += -std=c++14

  1. #include
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24609271

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档