Or make _thread_runner a static member function of Thread class.
2009/10/27 Leonel Flor?n Selles < leonel06033 at cfg.jovenclub.cu >:
error: argument of type ‘int (Cpacman::)(void*)’ does not match ‘int ()(void)’
Unfortunately, you can’t use a C++ member function with SDL_CreateThread().
You need to do something like this:
#include “SDL.h”
class Thread ? ?{
friend int _thread_runner(void*);
public:
Thread();
virtual ~Thread();
void start();
int wait();
void kill();
protected:
int _run();
virtual int run();
SDL_Thread* thread;
};
Thread::Thread() ? ?{
thread = 0;
}
Thread::~Thread() ? {
kill();
}
void Thread::start() ? ?{
if (thread) return;
thread = SDL_CreateThread(_thread_runner, this);
}
int Thread::wait() ?{
int ret = 0;
if (!thread) return 0;
SDL_WaitThread(thread, &ret);
return ret;
}
void Thread::kill() {
if (!thread) return;
SDL_KillThread(thread); // does nothing in SDL 1.3
thread = 0;
}
int Thread::_run() {
int ret = run();
thread = 0;
return ret;
}
int Thread::run() ? {
return 0;
}
int _thread_runner(void* data) ?{
return reinterpret_cast<Thread*>(data)->_run();
}
See attached for a timer thingy (not tested with SDL 1.3, works on 1.2)._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listin
----- Messaggio originale -----
Da: “Kenneth Bull”
A: “SDL Development List”
Inviato: Gioved?, 29 ottobre 2009 9:42:23 GMT +01:00 Amsterdam/Berlino/Berna/Roma/Stoccolma/Vienna
Oggetto: Re: [SDL] threads problem with Class
2009/10/27 Leonel Flor?n Selles : > error: argument of type ‘int (Cpacman::)(void*)’ does not match ‘int ()(void)’ Unfortunately, you can’t use a C++ member function with SDL_CreateThread(). You need to do something like this: #include “SDL.h” class Thread { friend int _thread_runner(void*); public: Thread(); virtual ~Thread(); void start(); int wait(); void kill(); protected: int _run(); virtual int run(); SDL_Thread* thread; }; Thread::Thread() { thread = 0; } Thread::~Thread() { kill(); } void Thread::start() { if (thread) return; thread = SDL_CreateThread(_thread_runner, this); } int Thread::wait() { int ret = 0; if (!thread) return 0; SDL_WaitThread(thread, &ret); return ret; } void Thread::kill() { if (!thread) return; SDL_KillThread(thread); // does nothing in SDL 1.3 thread = 0; } int Thread::_run() { int ret = run(); thread = 0; return ret; } int Thread::run() { return 0; } int _thread_runner(void* data) { return reinterpret_cast(data)->_run(); } See attached for a timer thingy (not tested with SDL 1.3, works on 1.2).
_______________________________________________ SDL mailing list SDL at lists.libsdl.org http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org