[SDL] SDL_CreateThread with C++ method as a parameter

Brian brian.ripoff at gmail.com
Sat Mar 22 06:51:17 PDT 2008


The following compiles and runs for me:

class Tetra {
public:
    void runThread()
    {
        SDL_Thread *thread = SDL_CreateThread(&StaticThreadProcGravity,this);
        int ret;
        SDL_WaitThread(thread,&ret);
        std::cout << "thread ended with status " << ret << '\n';
    }

    int ThreadGravity() { return 0; }

   static int StaticThreadProcGravity(void* pParam)
   {
       return ((Tetra*)pParam)->ThreadGravity();
   }
};

Is there anything that you are doing differently (apart from the body
of the thread function itself).

On Sat, Mar 22, 2008 at 12:46 PM, PS3-690 <daimler3 at googlemail.com> wrote:
> Hello,
>
> I have a problem with SDL_CreateThread. I want to use it with a C++ method:
> SDL_CreateThread(function, NULL);
> But then I get an Error:
> "argument of type `int (Class::)(void*)' does not match `int (*)(void*)"
>
> Searching with Google didn't helped me:
> static int Tetra::StaticThreadProcGravity(void* pParam)
> {
>     return ((Tetra*)pParam)->ThreadGravity();
> }


More information about the SDL mailing list