c++ - Why does the same header file have to be included twice? -
i've finished building programme in have main.cpp file , own static library, let's phone call mylib , it's made mylib.h , mylib.cpp files.
mylib.h , mylib.cpp create static library.
in static library, create utilize of boost functions , classes own classes , functions in mylib.cpp can things: in mylib.cpp add together lines
#include <boost/math/distributions/binomial.hpp> #include <boost/math/tools/roots.hpp> to mylib.cpp
now mylib.h contains function declarations, , class definitions, mylib.cpp has implementation of functions , class definitions, , since of functions, require classes declared in mylib.h, #include "mylib.h" must added mylib.cpp file (i suspect if functions did not, mylib.cpp compiled object file without mylib.h file needing included long whatever uses object file include mylib.h - since functions utilize classes, mylib.cpp includes mylib.h). acceptable implementation file require header file compilation object file (and inclusion .a file)? can't quite fathom if bad or not - thought thought supposed separate?
this totally normal , way things done in c/c++. header file contains declarations needed utilize library, source file contains definitions needed build library. source file includes header file classs, functions, etc need declared before can defined.
c++ compilation
No comments:
Post a Comment