error :: make_unique는 'std'의 구성원이 아닙니다.
코드 검토에 게시 된 다음 스레드 풀 프로그램을 컴파일하여 테스트하려고합니다.
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과 호환되는 경우에도 컴파일러에서 사용하지 못할 수 있습니다.
그러나 자신의 구현을 쉽게 롤링 할 수 있습니다.
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 에 C ++ 14로 투표 된 최종 버전 이 있습니다. 여기에는 배열을 다루는 추가 함수가 포함되어 있지만 일반적인 아이디어는 여전히 동일합니다.)
최신 컴파일러가있는 경우 빌드 설정에서 다음을 변경할 수 있습니다.
C++ Language Dialect C++14[-std=c++14]
이것은 나를 위해 작동합니다.
1.gcc 버전> = 5
2. CXXFLAGS + = -std = c ++ 14
3. #include <memory>
XCode로 작업하는 동안 이런 일이 발생합니다 (2019 년에 XCode의 최신 버전을 사용하고 있습니다 ...). 빌드 통합을 위해 CMake를 사용하고 있습니다. CMakeLists.txt에서 다음 지시문을 사용하여 문제를 해결했습니다.
set(CMAKE_CXX_STANDARD 14).
예:
cmake_minimum_required(VERSION 3.14.0)
set(CMAKE_CXX_STANDARD 14)
# Rest of your declarations...
제 경우 에는 std = c ++ 업데이트가 필요했습니다.
내 gradle 파일에서 이것은
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"
}
}
....
}
이 줄을 바꿨어
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"
}
}
....
}
그게 다야 ...
참고 URL : https://stackoverflow.com/questions/24609271/errormake-unique-is-not-a-member-of-std
'program story' 카테고리의 다른 글
| 형제 노드에 특정 값이있는 경우 XPath를 사용하여 노드를 선택하는 방법은 무엇입니까? (0) | 2020.11.01 |
|---|---|
| gradle-wrapper를 사용할 때 다운로드하지 않고 로컬 시스템에서 gradle zip을 사용하는 방법 (0) | 2020.11.01 |
| Pascal Case를 문장으로 변환하는 가장 좋은 방법 (0) | 2020.11.01 |
| 긴 상수 목록을 Python 파일로 가져 오기 (0) | 2020.11.01 |
| 문자열을 이스케이프한다는 것은 무엇을 의미합니까? (0) | 2020.11.01 |