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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
fichier .h
#ifndef DEF_PTREAD
#define DEF_PTREAD
#include <pthread.h>
class c_thread
{
public:
/*constructeur*/
c_thread();
/*destructeur*/
~c_thread();
/* methode*/
/*creation du thread*/
int m_thread_create();/*1 -->static void m_thread_call();*/
/*atribut*/
protected:
virtual void m_call_thread(){};/*3 --> ok*/
private:
/*methode privée*/
static void *m_thread_call(void *this_); /*2 --->[protect virtual m_call_thread]*/
/*obtenir le handle cree precedament*/
int get_handle();
/*attribut priver*/
pthread_t handle_;
};
class B{
public:c_thread
virtual void m_call_thread()
{
std::cout << "thread started" << std::endl;
};
};
#endif //fin des macro
fichier .cpp
#include "my_class_ptrhead.h"
/*constructeur*/
c_thread::c_thread() {};
/*destructeur*/
c_thread::~c_thread(){};
/*creation du thread et renvoi du handle*/
int c_thread::m_thread_create()
{
pthread_create(&handle_, 0, c_thread::m_thread_call, static_cast<void *>(this));
return c_thread::get_handle() ;
};
/*obtenir le handle cree precedament*/
int c_thread::get_handle()
{
return handle_;
};
void *c_thread::m_thread_call (void *data){
c_thread *base = static_cast<c_thread *>(data);
base->m_call_thread();
return 0;
};
fichier main.cpp
#include <iostream>
#include <string>
#include <cstring>
#include "my_class_ncurse.cpp"
#include "my_class_ptrhead.cpp"
int main()
{
c_thread thread_p;
int id1_H = 0;
id1_H = thread_p.m_thread_create();
std::cout << id1_H << std::endl;
};
erreur:
In file included from my_class_ptrhead.cpp:1,
from main.cpp:5:
my_class_ptrhead.h:28: erreur: two or more data types in declaration of m_call_thread |
Partager