error::make_unique is not a member of ‘std’
我正在尝试编译代码审查中发布的以下线程池程序以对其进行测试。
https://codereview.stackexchange.com/questions/55100/platform-independant-thread-pool-v4
但是我得到了错误
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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>(); |
但是,您可以轻松地滚动自己的实现:
1 2 3 4 | template<typename T, typename... Args> std::unique_ptr< T > make_unique(Args&&... args) { return std::unique_ptr< T >(new T(std::forward<Args>(args)...)); } |
(仅供参考,这是在C ++ 14中投票的
如果您有最新的编译器,则可以在构建设置中更改以下内容:
1 | C++ Language Dialect C++14[-std=c++14] |
这对我有用。
1.gcc版本> = 5
2.CXXFLAGS + = -std = c ++ 14
3. #include <内存>
就我而言,我需要更新std = c ++
我的意思是在我的gradle文件中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | android { ... defaultConfig { ... externalNativeBuild { cmake { cppFlags"-std=c++11","-Wall" arguments"-DANDROID_STL=c++_static", "-DARCORE_LIBPATH=${arcore_libpath}/jni", "-DARCORE_INCLUDE=${project.rootDir}/app/src/main/libs" } } .... } |
我改变了这条线
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | android { ... defaultConfig { ... externalNativeBuild { cmake { cppFlags"-std=c++17","-Wall" <-- this number from 11 to 17 (or 14) arguments"-DANDROID_STL=c++_static", "-DARCORE_LIBPATH=${arcore_libpath}/jni", "-DARCORE_INCLUDE=${project.rootDir}/app/src/main/libs" } } .... } |
而已...
这是我在使用XCode时发生的情况(我正在使用2019年最新版本的XCode ...)。我正在使用CMake进行构建集成。在CMakeLists.txt中使用以下指令为我修复了该指令:
例:
1 2 3 4 | cmake_minimum_required(VERSION 3.14.0) set(CMAKE_CXX_STANDARD 14) # Rest of your declarations... |