Having compile issue when using atomic with class based.
error: use of deleted function ‘std::atomic<_Tp>::atomic() [with _Tp = node]’ stack() { ^
/usr/include/c++/5/atomic:185:7: note: ‘std::atomic<_Tp>::atomic() noexcept [with _Tp = node]’ is implicitly deleted because its exception-specification does not match the implicit exception-specification ‘’ atomic() noexcept = default; ^
#include <atomic>
#include <cstdlib>
#include <memory>
class node
{
private:
int data;
bool hasTransaction;
public:
node(int& data) : data(data), hasTransaction(true) {}
node() : data(10), hasTransaction(true) {}
};
class stack {
std::atomic<node> head;
public:
void push(int data) {
node new_node(data);
node current = head.load(std::memory_order_relaxed);
while (!head.compare_exchange_strong(
current,
new_node,
std::memory_order_release,
std::memory_order_relaxed))
;
}
stack() {
node a;
std::atomic_init(&head, a);
head.store(a);
};
};
int main()
{
stack s;
s.push(1);
s.push(2);
s.push(3);
}