c++ - Why doesn't library source file include its header -


i trying explore opencv.

when looked mat class, can see defined in mat.hpp, located in include folder. however, when attempted search corresponding mat.cpp, found class definition located in matrix.cpp. suppose difference in file name not problem, long includes mat.hpp. however, header mat.hpp wasn't included either. know compiler still able compile, far know, bad programming practice.

so, question is, true bad practice not include header file in source file? there reason why should not included?

i understand not need explore detailed implementation of library, question out of curiosity.

here #include part of matrix.cpp

#include "precomp.hpp" #include "opencl_kernels_core.hpp" #include "bufferpool.impl.hpp" 

and here #include part of mat.hpp

#include "opencv2/core/matx.hpp" #include "opencv2/core/types.hpp" #include "opencv2/core/bufferpool.hpp" 

the short answer is: that's how project evolved.

the long answer is: opencv did (and still does) declare many of functions , classes in core.hpp while many .cpp files hold implementations. in case, matrix-specific functions (and implementations mat) in matrix.cpp , definitions classes, mat, in core.hpp.

as project grew, things seem split (probably easier manage). can see in this commit, class mat moved out of core.hpp own mat.hpp (named such match class name). source file matrix.cpp include mat.hpp, though indirectly (through precomp.hpp , core.hpp).

i don't think confusion intentional, incidental. bad practice? so, thats decide.

disclaimer: have not worked on opencv source, did use extensively time.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -