I почти решил проблемы с моим кодом с помощью пользователей stackoverflow, но теперь у вас другая проблема. Мой код теперь выглядит следующим образом:передовая декларация 'struct bb', классы
#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 ===|
@Mat Я думаю, что проблему зависимости можно устранить, поставив определения соответствующих методов в файлы реализации. Тем не менее, дизайн все еще опасен. – juanchopanza