这个报错是因为没有找到Thread类的虚函数表(vtable)和Thread类的typeinfo信息。解决方法是在Thread类中声明一个虚函数(可以是一个空函数),这样就会自动生成虚函数表和typeinfo信息。

例如,在Thread类中添加一个空的虚函数:

class Thread {
public:
    virtual ~Thread() {}
    virtual void dummy() {}
};

然后重新编译即可:

g++ polymorphism_t.cpp -lpthread
使用编译命令:g++ polymorphism_tcpp -lpthread出现如下报错:usrbinld tmpccwHN6qNo warning relocation against _ZTV6Thread in read-only section text_ZN6ThreadC2Ev_ZN6ThreadC5Evusrbinld tmpccwHN6qNo in function ThreadT

原文地址: https://www.cveoy.top/t/topic/jdfD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录