I am aware how to solve basic circular dependency example, with two classes, where each needs to know that the other one exists.
However, I am now in situation, where the example is more complicated, and forward declaration is not something, that can fix that issue.
Consider these three files
// my_thread.hpp
template<typename Function> class my_thread;
template<typename Return, typename... Input>
struct my_thread<Return(Input...)>
{
void somefunction() { thread_manager::static_function(); }
}
// thread_manager.hpp
struct thread_manager
{
static void static_function() { }
std::list<some_class::thread_type> threads;
}
// some_class.hpp
struct some_class
{
using thread_type = my_thread<int(some_class*)>
}
Now, obviously my_thread.hpp
requires whole thread_manager
(or at least it's function?). thread_manager
requires using
directive from some_class
and some_class
is dependent on my_thread
. Since STL containers require complete type template parameters, I can't forward declare my_thread
. I can not even put out definition of my_thread<T>::somefunction()
, since it's template function and requires to be placed in header.
My question is, how do I resolve this circular dependency?
And funny thing, MSVC does not require #include "thread_manager" in
my_thread.hppfor some reason. I don't know how it knows about
thread_manager`.