c++ - Header-Only circular dependency -


i having problems circular dependency in head-only library c++ have not been circular dependency problem when using source files instead of making header-only.

the situation equal this:

there 4 files 2 classes , b. every class has got header file (e.g. "a.hpp") , implementation file (e.g. "a.tpp").

the dependencies follows:

  • a's header requires b' header
  • a's impl requires b's header
  • b's header requires nothing forward declaration a
  • b's impl requires a's header

so in source-based library fine following order of source file inclusion , compilation:

  • b.hpp
  • a.hpp
  • a.tpp or b.tpp (order here not important)

my files structured in way:

file content a.hpp:

#ifndef a_h #define a_h #include "b.hpp" class { ... }; #include "a.tpp" #endif 

file content a.tpp:

#ifndef a_h     #error "do not include file directly." #endif // ... implementations a.hpp 

file content b.hpp:

#ifndef b_h #define b_h class a; class b { ... }; #include "b.tpp" #endif 

file content b.tpp:

#include "a.hpp" #ifndef b_h     #error "do not include file directly." #endif // ... implementations b.hpp 

so question is: there solution breaking unnessesary circular dependency happens due fact using header-only solution library?


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -