I try to create two classes which include inheritance, but I think this construct is not possible to build ... maybe you are able to help me or tell my that this is realy impossible.
1 2 3 4 5 6 7 8 9 10 11 12
class A
{
...
public:
B* funktion(){ returnnew B();}
...
};
class B : public A
{
...
}
this ist only an example, with the things, that didn't work. The problem is that A uses B and B inherits from A.
I tried it with forward declaration, but it also didn't work ...
Well since you aren't actually using B, you can use forward declaration. In this case however, you can't put the body of the function in the .hpp because new needs to know how large B is, etc.
Just move the function body to A's cpp file and forward declaration will work fine.
^ as long as it is after the 'B' declaration it will work.
However, the design looks weird. You've got a factory that has to know about its derived classes, ¿what are you trying to do?
Thank you for your help. Only one f***ing #include was missing and the output of the compiler was really confusing.
This should be a first design of a Starsystem.
A = AstronomicObject and B = Satellite. funktion() stands for createSatellite(...). Every AO can have satellites and satellites can also have other satellites.
I'm new to oop and so it is possible that my design is weird ...