vendredi 30 avril 2021

c++ error in my thread constructor passing the function

I'm trying to make a thread every time a call a function from a class, but i can't pass the function correctly:

file.h

#include <thread>

class Class
{
public:
    Class(int a);
    void ThreadBase(void (*func));
    int CreateThread(void (*func));
};

file.cpp

#include <thread>
Class::Class(int a)
{
    /**
     *  ...
     */
}

void Class:ThreadBase(void (*func))
{
    while(1)
    {
        /**
         *  ...
         */
    }
}

int Class:CreateThread(void (*func))
{
    std::thread th(Class::ThreadBase, func);
}

Error:

error: reference to non-static member function must be called

Aucun commentaire:

Enregistrer un commentaire