xcode 命名空间“std”中没有名为“atomic”的类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15720392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:06:02  来源:igfitidea点击:

No type named 'atomic' in namespace 'std'

c++xcodec++11stdatomic

提问by Hobbyist

Why doesn't

为什么不

std::atomic<int> index;

Work?

工作?

Currently using LLVM 3.1 with these params

当前使用带有这些参数的 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)

回答by Jesper Juhl

There are several things that need to be true for your code to work:

有几件事情需要你的代码才能工作:

  1. You need to #include <atomic>

  2. You need to compile the code as C++11 or C++14 (-std=c++11or -std=c++14(or c++0xfor older compilers))

  3. Your compiler and standard library needs to support enough of C++11 to provide atomic(http://clang.llvm.org/cxx_status.html)

  1. 你需要 #include <atomic>

  2. 您需要将代码编译为 C++11 或 C++14(-std=c++11-std=c++14(或c++0x对于较旧的编译器))

  3. 你的编译器和标准库需要支持足够的 C++11 来提供atomichttp://clang.llvm.org/cxx_status.html

回答by tamtam

Adding -std=c++11to CXXFLAGS in my Makefile -> that works for me!

-std=c++11在我的 Makefile 中添加到 CXXFLAGS -> 对我有用!

回答by 524888 Wusi

You need to write it as the following to defined variable.

您需要将其编写为以下定义的变量。

    std::atomic<std::int> index;