Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use of deleted function - std::atomic

Tags:

c++

gcc

This is the declaration I have in .h file:

static std::atomic<int> OrdersExecutorIdCounter;

This is initilization from .cpp file:

std::atomic<int> ActionBasedOrdersExecutor::OrdersExecutorIdCounter = 0;

It compiles just fine in VC++, but in gcc 4.8 I get this error:

error: use of deleted function ‘std::atomic<int>::atomic(const std::atomic<int>&)’

How can I solve this problem?

like image 386
Oleg Vazhnev Avatar asked Sep 19 '14 18:09

Oleg Vazhnev


People also ask

What is use of deleted function?

Use the DELETE function to erase the data contents of a specified field, value, or subvalue and its corresponding delimiter from a dynamic array.


2 Answers

You can directly initialise the atomic variable, which does not require deleted copy constructor, eg:

std::atomic<int> ActionBasedOrdersExecutor::OrdersExecutorIdCounter{0};
like image 159
Rafal Mielniczuk Avatar answered Oct 01 '22 09:10

Rafal Mielniczuk


You don't need (or want) to initialize your atomic integer to 0 (the int value would be 0 initialized for a global).

like image 44
Basile Starynkevitch Avatar answered Oct 01 '22 09:10

Basile Starynkevitch