Reputation: 396
Unfortunately I got an include-structure which leads into a problem where class Z needs to include class A because of inheritage, but Z gets included first. A littlebit more clear:
A.h includes B.h
B.h includes C.h
C.h includes D.h
D.h includes Z.h
So Z gets defined before A. This results in an error saying "Baseclass A undefined". I can't use forward decleration, because in every class I call functions of the classes I include.
I hope there is any solution to come around that problem.
Upvotes: 0
Views: 48
Reputation: 30604
I hope there is any solution to come around that problem.
No, not a quick fix. You need to restructure your code, at least w.r.t. to the includes.
You could explore templates to assist, but they may be more hassle that needed.
Unless the "is-a" relationship is applicable, you can remove A
as a base class and move it to be a member (via. std::shared_ptr<A>
or std::unique_ptr<A>
) and forward declare A
. If the "is-a" relationship is applicable, then you have circular dependencies that you will need to break somehow (again, smart pointers can help).
You don't mention the cpp file use or requirements; use the cpp files (Z.cpp) to isolate the code that does the calling of the A
members, that way the header requirements are lowered.
Upvotes: 1