I have class A (in A.h) which depends on class B in (B.h) and vice versa. Forward declaring the used functions works, but this means I have to update everywhere where I forward declared those functions in the future, ex, if I remove, or change argument in those functions they must all be updated to reflect change. I don’t feel this is good practice. Is there a way around this?
Thanks
If you only need to work with pointers or references to a class at the declaration level, you can do it like this:
A.h
B.h
B.cpp
Mutual dependencies like this are tough to deal with but sometimes unavoidable.
If
AandBdepend on the implementations of each other, then you’ve got a system design problem that you need to resolve before proceeding further.