My first question is: Is there any way to access the members of struct in an atomic<struct>
object?
For example, I get the compiler error:
struct std::atomic<node>’ has no member named ‘data’ a.data = 0;
in this segment
struct node{
int data;
node* next;
};
int main(){
atomic<node> a;
a.data = 0;
}
I can work around it by creating a temporary node like so:
atomic<node> a;
node temp;
temp.data = 0;
a.store(temp);
but this doesn't seem very elegant.
The second question is, what if I have a pointer to an atomic object? Is there anyway to access the members of the node directly? Obviously the following does not compile, how would I change this to store 0 in the value of the node at b?
atomic<node> b = new node;
b->data = 0;
This is a solution I've found, but again, is there a more elegant way of doing this??
atomic<node> *b;
node temp;
temp.data = 0;
b->store(&temp);
And lastly, what is the difference between atomic<node*>
and atomic<node>*