在创建调用成员函数的线程时,传递指向当前类的指针和传递引用之间有区别吗?
从下面的示例中,method1的行为是否与method2相同?是否存在任何差异?
class MyClass
{
public:
MyClass(){};
~MyClass(){};
void memberFunction1()
{
//method 1
std::thread theThread(&MyClass::memberFunction2, this, argumentToMemberFunction2)
//method 2
std::thread theThread(&MyClass::memberFunction2, std::ref(*this), argumentToMemberFunction2)
}
void memberFunction2(const double& someDouble){};
}
std::ref
reference_wrapper
作为第一个对象(内部)指针调用时,将其作为引用传递在语法上是可疑的。 - ShadowRanger