我想创建一个线程对象,成员函数“run”可以被覆盖。当我添加“虚拟”这个词时,它会失败。有人可以帮助我 - 我如何制作线程对象。该对象可以被继承,并且成员函数可以被覆盖。线程虚拟成员函数
#include <iostream>
#include <process.h>
using namespace std;
class thread
{
private:
static void gangplank(void *ptr)
{
((thread *)ptr)->run();
}
public:
void start()
{
_beginthread(&this->gangplank,0,(void *)this);
//this->gangplank((void *)this);
}
virtual void run()
{
cout<<1;
}
~thread()
{
_endthread();
}
};
class d:public thread
{
public:
void run()
{
cout<<2;
}
};
int main()
{
d a;
a.start();
return 0;
}
错误消息:
“text.exe已停止工作 - Windows正在检查一个解决问题的办法” 它没有编译错误
。
当你说“它会运行失败”,你是什么意思?你会得到什么错误? – doctorlove
错误消息是“text.exe已停止工作 - Windows正在检查问题的解决方案” – Ken