Let's say I have two classes:
class One {
Two *somevar = new Two;
// (...)
};
class Two {
One *somevar = new One;
// (...)
}
And it's impossible to compile something like that. How to handle it?
Let's say I have two classes:
class One {
Two *somevar = new Two;
// (...)
};
class Two {
One *somevar = new One;
// (...)
}
And it's impossible to compile something like that. How to handle it?
Since all that you are nesting is a pointer, try:
class Two;
class One {
Two *somevar = new Two;
// (...)
};
class Two {
One *somevar = new One;
// (...)
}
By forward-declaring class Two, you are giving the compiler enough information to be able to create the pointer inside class One. If you were trying to nest the classes themselves and not just pointers, then there would not be any way to solve the problem.
I think i found a solution:
// class Type instead of Type
// so:
class Two *somevar = new class Two;