假设我有一个名为 Turtle 的抽象类。在课堂上,我在自己的线程上有一个函数,它接受 Turtle 的输入。编译器说我不能使用抽象类型 Turtle 的输入。我想要发生的是函数接受派生类的输入,而不是抽象 Turtle 类。我应该如何解决这个问题?
#include <thread>
class Turtle
{
std::thread T_thread;
public:
virtual void foo(Turtle T) = 0;
//tried making this virtual as well
void do_stuff(Turtle T)
{
foo(T);
}
Turtle()
{
T_thread = std::thread(do_stuff, this);
}
};