-
Innerclass problem
I came across this problem:
I have two classes (classA & classB). classA has an inner class: classC
Normally, to create a member of type inner class classC in classB I would do this:
ClassA::ClassC member_;
The definitions are in header files.
Now I need classB in classA so I include classB. h in classA.h
A variable of type classC needs to be passed with the constructor of classB.
I can't include classA.h in class be because I already included ClassB. in classA.h
The normal way (I think) to solve this problem (if I needed class A in classB.h is to say that classB is a class like this:
Code:
class classB
{
private:
class classA;
classA my_classA_;
...
}
But now I need classC in classB
and
class classA::classC;
doesn't work.
I solved the problem by taking classC out of classA but techicaly classC is part of classB so I'd rather put it in there.
Any ideas?
-
Uh... a little confusing (too much alphabet soup with those class names floating in my head). If you can give more of an idea to the application of this, it'd be easier to come up with a solution.
Off the top of my head, though, I'd ask whether classA actually needs to include classB.h? Can any of the members of classA of type classB be made references or pointers? Without the actual code/problem, it is hard to tell if this is a viable solution, but replacing the include with a forward declaration would solve the problem.