Copy-initialization of atomic variables in C++11
atomic, c++, c++11, initialization, stdatomic
Solution
Try:
std::atomic_int turnX(5);
This uses a `constexpr` constructor, so it should be constructed as constant initialization (i.e. at load time).
Problem
Can atomic variables in C++11 be initialized globally? For example: ``` std::atomic_int turnX = 5; int main() { /* ... */ } ``` This fails with: ``` error: deleted function ‘std::atomic<int>::atomic(const std::atomic<int>&)’ ``` Looking at `<atomic>`, it does give an idea that this is not allowed. Am I correct in making a statement that atomic variables can be assigned values only from within a function?