我的代码如下所示:
void C::addB(std::atomic<B>& b)
{
B* b2 = b.load();
B newValue = B();
bool result = b.compare_exchange_weak(b2, newValue, std::memory_order_relaxed, std::memory_order_release);
}
并且编译器一直抱怨签名与compare -exchaneg_weak的三成员重载形式不匹配:
note: candidate expects 3 arguments, 4 provided
答案 0 :(得分:3)
您的代码比我发布的代码提供了更多错误消息。最相关的是
error: cannot convert ‘B’ to ‘B*’ in initialisation
note: no known conversion for argument 1 from ‘B*’ to ‘B&’
表示您在需要对象时声明指针:
B b2 = b.load();
答案 1 :(得分:0)
http://en.cppreference.com/w/cpp/atomic/atomic/compare_exchange
从上面的URL中引用原型并相应地传递参数。