Search code examples
c++structatomicstdatomic

Issue with std::atomic and custom structs


Can't seem to do this (see code) for some reason. Looked at documentation, there doesn't seem to be a reason for this not to work...

struct vector {
    float x, y, z;
};
std::atomic<vector> Name = {0};

It says I can't initialize it with an initializer list, and when I go to use it in my code, it says it has no members.

Name.x = 4.f;
Name.y = 2.f * Name.x;
Name.z = 0.1f;

Solution

  • It's Name._My_val.x, Name._My_val.y, Name._My_val.z not Name.x, Name.y, Name.z

    Why it is no one told me this is beyond me, but whatever.