为什么不
std::atomic<int> index;
工作?
当前使用带有这些参数的 LLVM 3.1
C Language Dialect GNU [-std=gnu99]
C++ Language Dialect [-std=c++11]
C++ Standard Library libc++(LLVM C++ standard library with C++11 support)
要使您的代码正常工作,需要满足以下几点:
你需要#include <atomic>
您需要将代码编译为 C++11 或 C++14(-std=c++11
或-std=c++14
(或c++0x
对于较旧的编译器))
您的编译器和标准库需要支持足够的 C++11 才能提供atomic
( http://clang.llvm.org/cxx_status.html )
在我的 Makefile 中添加-std=c++11
到 CXXFLAGS -> 这对我有用!
您需要将其编写为以下定义的变量。
std::atomic<std::int> index;