我有这样的代码:
class Animator{
public:
private:
bool _running;
atomic<bool> _waiting;
};Visual说Error 2 error C2248: 'std::atomic<bool>::operator =' : cannot access private member declared in class 'std::atomic<bool>' d:\programmierung\uncertainty\uncertainty\uncertainty\animator.h 113
我看不出这个类和只有原子作为成员的最小类之间的区别,这是可行的。
发布于 2014-03-03 14:08:29
最有可能的是,您的最小测试类的赋值运算符根本没有被使用,因此没有实例化。如果要显式调用其赋值运算符,则应该会看到相同的错误。原子不支持分配给另一个std::原子。
发布于 2014-03-03 14:21:53
您错过了实例变量的初始化:
#include <atomic>
class Animator
{
public:
Animator();
private:
bool _running;
std::atomic<bool> _waiting;
};
Animator::Animator() : _running(false), _waiting(false) {
}类std::atomic没有赋值运算符,但如果使用默认构造函数而不使用默认值,则将使用此运算符。
https://stackoverflow.com/questions/22148717
复制相似问题