rendered paste body
$ g++ -lpthread -c cppthread.c
cppthread.c: In static member function `static void* Thread::static_run(void*)':
cppthread.c:38: error: `void*' is not a pointer-to-object type
cppthread.c:38: error: cannot call member function `void* Thread::Arg() const' without object
---------------------------------------------------
#include <pthread.h>
class Thread
{
public:
Thread();
virtual void run();
virtual void stop();
virtual bool running() const;
virtual void join();
static void sleep();
virtual ~Thread();
void Arg(void* a){Arg_ = a;};
protected:
static void *static_run(void*);
virtual void *main(void*);
void *Arg() const {return Arg_;}
private:
Thread(const Thread&);
Thread& operator=(const Thread&);
pthread_t tid;
void *Arg_;
};
Thread::Thread() {}
void Thread::run()
{
int code = pthread_create(&tid, NULL, &Thread::static_run, this);
return;
}
/*static */
void * Thread::static_run(void* pthis)
{
Thread *pt = (Thread*)pthis;
return pthis->main(Arg());
}