【发布时间】:2014-08-27 20:34:50
【问题描述】:
我正在尝试编译发布在代码审查上的以下线程池程序以对其进行测试。
https://codereview.stackexchange.com/questions/55100/platform-independant-thread-pool-v4
但我收到了错误
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>();
【问题讨论】:
-
你用的是什么编译器?
-
你使用什么编译器/标志?
make_unique是一个 c++14 特性 -
很可能你没有它的代码,因为它不是 c++11 的一部分?
-
他在某种程度上使用了 c++14 的特性,而你没有。
-
会有一个 make_unique 的实现。没那么难 ;) msdn.microsoft.com/en-us/library/dn439780.aspx
标签: c++ c++11 compiler-errors c++14 unique-ptr