I know there are many answers on this site about circular dependency, but none that I found can solve my problem, mainly because my definitions are inlined in the headers.
I am writing a library in C++11. For simplification, I have two classes:
Exception
inException.hpp
CallStack
inCallStack.hpp
.
The dependencies are:
Exception
makes heavy use ofCallStack
(both in declarations and definitions it needs a complete type ofCallStack
) soException.hpp
includesCallStack.hpp
.CallStack
doesn't needException
at all in it's declaration. It just needs to throw anException
(calls a non-defaultException
constructor) in one of the member definition (operator[]
), so it needs a complete type ofException
in a definition.
I know that if I write the definition in a .cpp
file, I resolve the problem, but since all methods and constructors don't have more than 2 lines, I have chosen to define them inline, which means that they need to be defined in the .hpp
header.
The solution to have a forward declaration before the declaration and to include the other header between the declaration and the definition doesn't work, as, I have said, Exception
needs a complete type of CallStack
in its declaration.