1.

thread在类的成员函数中的使用

#include <thread>
#include <iostream>
using namespace std;
class Wrapper { public: void member1() { cout << "member1" << endl; }
void member2(const char *arg1, unsigned arg2) { cout << "i am member2 and my first arg is ("
         << arg1 << ") and second arg is ("
         << arg2 << ")" <<endl; }
std::thread member1Thread() {
return thread(&Wrapper::member1, this); }
std::thread member2Thread(
const char *arg1, unsigned arg2) { return thread(&Wrapper::member2, this, arg1, arg2); } }; int main() { Wrapper *w = new Wrapper(); std::thread tw1 = w->member1Thread(); tw1.join(); w->member2Thread("hello", 100).detach(); return 0; }

 

相关文章:

  • 2021-12-31
  • 2021-07-30
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2022-03-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案