-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path多线程在类中.cpp
45 lines (41 loc) · 883 Bytes
/
多线程在类中.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* @Author: your name
* @Date: 2020-04-10 18:02:41
* @LastEditTime: 2020-04-10 18:58:01
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /C++课程学习记录/thread多线程/point.cpp
*/
#include <iostream>
#include <thread>
using namespace std;
// 3.functor (Funciton Object)
class Base {
public:
// 重载operator ()
void operator()(int x) {
while (x-- > 0) {
cout << x << endl;
}
}
// 非静态成员
void fun1(int x) {
while (x-- > 0) {
cout << x << endl;
}
}
// 静态成员
static void fun2(int x) {
while (x-- > 0) {
cout << x << endl;
}
}
};
int main() {
thread t(Base(), 10);
// Base b;
// thread t(&Base::fun1, &b, 10);
// thread t(&Base::fun2, 10);
t.join();
return 0;
}