#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <pthread.h>
template<typename T>
class MyTest {
public:
MyTest(){};
~MyTest(){};
void start();
void run_loop();
};
void* main_loop(void* ctx) {
MyTest* qw = static_cast<MyTest*>(ctx);
qw->run_loop();
return NULL;
}
template<typename T>
void MyTest<T>::start() {
pthread_t tid;
pthread_create(&tid, NULL, main_loop, this);
}
int main() {
MyTest *tmp = new MyTest();
tmp->start();
return 0;
}
为代码如上,子类会继承这个模板基类,作为一个线程,请问如何实现这个线程入口?