我试图通过基类的另一个函数向基类的函数发送派生指针,但由于某种原因,它抱怨:错误:第 8 行的不完整类型“struct Derived”的无效使用。
#include <iostream>
using namespace std;
class Derived;
class Base
{
public:
void getsomething(Derived *derived){derived->saysomething();} //This is line 8
void recieveit(Derived *derived){getsomething(&*derived);}
};
class Derived : public Base
{
public:
void giveself(){recieveit(this);};
void saysomething(){cout << "something" << endl;}
};
int main()
{
Base *b = new Base;
Derived *d = new Derived;
d->giveself();
return 0;
}
你知道我怎么能解决这个问题吗?