Usually in C ++, when I need interdependencies between classes, I use forward declarations in the header files, and then include both header files in each cpp file.
However, this approach breaks down when working with templates. Since the templates should be completely in the header files (apart from the case when I put the code in cpp and list the template class A<T>; for each T supported, this is not always possible, for example, when T is a lambda).
So, is there a way to declare / define interdependent patterns in C ++?
Code example
template<typename T> struct B; template<typename T> struct A { void RunA(B<T> *pB) {
If I start to do something with B in RunA() , I think I will get a "missing definition" error, because only the RunA() compiles only the forward declaration from B.
Perhaps there is some trick for organizing header files, for example. dividing each header into class definition and method definition files, and then including them in some fancy ways. Or maybe something can be done through the third / fourth grade. But I canβt imagine how to do this specifically.
C ++ 11/14/17 is fine (in particular, this is MSVC ++ 2017, toolset v141).
c ++ include c-preprocessor compilation templates
Serge Rogatch
source share