threadpool icon indicating copy to clipboard operation
threadpool copied to clipboard

普通成员函数的调用参数问题

Open windflowerly opened this issue 5 years ago • 6 comments

你好。 bind: .commit(std::bind(&Dog::sayHello, &dog)) 这个好像不能带参数。

windflowerly avatar Sep 01 '20 07:09 windflowerly

参数带在bind里啊,为什么不能带参数

qhq16 avatar Sep 03 '20 08:09 qhq16

晓得了。参数类型问题。

windflowerly avatar Sep 04 '20 12:09 windflowerly

这个是只能调用threadpool自己的成员函数吗

ZhuZouRong avatar Jun 23 '21 09:06 ZhuZouRong

用bind绑定类成员函数就可以使用commit了

qhq16 avatar Jun 23 '21 10:06 qhq16

namespace dao { class Impl : public IStore { public: virtual int del(const std::string& strId); };

std::threadpool executor; std::future test = executor.commit(std::bind(&dao::Impl::del, "id"));

是这样调用吗 编译报错 required from here /usr/include/c++/5/functional:1426:7: error: static assertion failed: Wrong number of arguments for pointer-to-member static_assert(_Varargs::value

ZhuZouRong avatar Jun 23 '21 11:06 ZhuZouRong

bind绑定非静态成员函数需要类对象指针,而且你绑定的是虚函数,你可以看看bind的用法

qhq16 avatar Jun 23 '21 11:06 qhq16