在 stackoverflow 用户的帮助下,我几乎解决了我的代码问题,但现在有不同的问题。我的代码现在看起来像这样:
#include <iostream>
#include <cmath>
#include <sstream>
using namespace std;
class root
{
public:
virtual ~root() {}
virtual root* addA(const root& a) const=0;
virtual root* addB(const root& b) const=0;
};
class bb;
class aa: public root
{
public:
aa() { }
aa(const aa& a) { }
root* addA(const root& a) const
{
return new aa();
}
root* addB(const root& b) const
{
return new bb();
}
};
class bb: public root
{
public:
bb() { }
bb(const bb& b) { }
root* addA(const root& a) const
{
return new aa();
}
root* addB(const root& b) const
{
return new bb();
}
};
int main(int argc, char **argv)
{
}
但是当我编译它时,它给出了错误:
/home/brain/Desktop/Temp/Untitled2.cpp||In member function ‘virtual root* aa::addB(const root&) const’:|
/home/brain/Desktop/Temp/Untitled2.cpp|30|error: invalid use of incomplete type ‘struct bb’|
/home/brain/Desktop/Temp/Untitled2.cpp|15|error: forward declaration of ‘struct bb’|
||=== Build finished: 2 errors, 0 warnings ===|