Here is a minimal example. I have a Base class that needs to know the Deriving class. In turn the Deriving class needs to know the Base class. So how can I define them, so that they know of each other's existence?
class Base {
Deriving* d;
public:
Base(Deriving* deriving) {
d = deriving;
}
void f() {
d->g();
}
};
class Deriving : public Base {
public:
Deriving() : Base(this) {}
g();
};
Here is what I tried and what the compiler said:
Defining Base first leads to error: 'Deriving' does not name a type. Defining Deriving first leads to error: expected class-name before '{' token. Declaring an incomplete type of Base or Deriving leads to error: invalid use of incomplete type 'class X'. I do not know what else to try.
Any help is greatly appreciated.