Bon, j'essaie de retransformer un fichier pour donner un coté OO propre.

Code code final désiré : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include <pthread.h>
#include <iostream>
#include <unistd.h>
 
using std::cout;
using std::endl;
 
class Threads
{
private:
	pthread_t leThread;
public:
	Threads();
 
	pthread_t* init();
	static void* demarrer(void* thread);
	virtual void traitement() {};
 
};
 
Threads::Threads()
{
}
 
pthread_t* Threads::init()
{
	if(!pthread_create(&(this->leThread),NULL,Threads::demarrer,static_cast<void *>(this)))
	{
		cout << "Creation du thread" << endl;
		return &(this->leThread);
	}
	else
	{
		cout << "Echec de la creation du thread" << endl;
		exit(0);
	}
}
 
 
static void* Threads::demarrer(void* thread)
{
	static_cast<Threads *>(thread)->traitement();
	pthread_exit(0);
}

Mais ce bazar ne marche pas, la console rale.

Code console : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
/TestInterface/lib$ c++ -g Thread.cpp -o Thread -lpthread
Thread.cpp:40: error: cannot declare member function ‘static void* Threads::demarrer(void*)’ to have static linkage

alors que si je fais ca, ca marche :s

Code code qui marche : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include <pthread.h>
#include <iostream>
#include <unistd.h>
 
using std::cout;
using std::endl;
 
class Threads
{
private:
	pthread_t leThread;
public:
	Threads();
 
	pthread_t* init();
 
	static void* demarrer(void* thread)
	{
		static_cast<Threads *>(thread)->traitement();
		pthread_exit(0);
	}
 
	virtual void traitement() {};
 
};
 
 
Threads::Threads()
{
}
 
pthread_t* Threads::init()
{
	if(!pthread_create(&(this->leThread),NULL,Threads::demarrer,static_cast<void *>(this)))
	{
		cout << "Creation du thread" << endl;
		return &(this->leThread);
	}
	else
	{
		cout << "Echec de la creation du thread" << endl;
		exit(0);
	}
}

une ame bien avisé pourrait m'éclairer?