1

我写了这段代码,但编译器给我一个错误,不知道为什么:S所以我想知道你能帮助我:这是一个用于简单线程实现的抽象类:

#ifndef THREAD_H
#define THREAD_H

#include <pthread.h>

class Thread {
public:
    void start();
    inline pthread_t getThread() const{
        return _thread;
    }

private:
    pthread_t _thread;
    inline static void* callRun(void* pObject){
        ((Thread*)pObject)->run();
        return (void*)0;
    }

protected:
    virtual void* run();
};

#endif  /* THREAD_H */

源代码是:

#include "Thread.h"

void Thread::start(){
    pthread_attr_t attrib;
    pthread_attr_init(&attrib);
    pthread_attr_setdetachstate(&attrib, PTHREAD_CREATE_JOINABLE);
    pthread_create(&_thread, &attrib, callRun, (void*)this);
    pthread_attr_destroy(&attrib);
}

并且类 PlayersManager 继承自 Thread

#ifndef PLAYERMANAGER_H
#define PLAYERMANAGER_H

#include "Thread.h"

class PlayersManager : public Thread {

private:
    void movePlayers();
    void checkPlayers();
    void* run();
};

#endif  /* PLAYERMANAGER_H */

但我得到下一个编译错误: build/Debug/GNU-Linux-x86/PlayersManager.o:(.rodata._ZTI14PlayersManager[_ZTI14PlayersManager]+0x8): undefined reference to `typeinfo for Thread'

知道发生了什么吗?谢谢。

4

0 回答 0