linux - C++. Avoiding cross-linking in multple files project -


i've been building many c++ projects university recently. consisted of multiple files 1 makefile. in prj folder makefile within, source files in src folder , headers in inc folder. makefile compiled object files in obj folder , linked final program.

i got many strange errors broke down that, e.g. i've included matrices.h in vector.h file , vector.h in matrix.h. compiler said methods not exist in matrix class.

i have include vector.h in matrix.h. then, include matrix in main.cpp. use sqrt() , pow() functions in files.

now wonder proper avoid declaring continously <cmath> library in vector.h, matrix.h , in main.cpp? i'd rather declare in vector.h , leave it. complier g++ , linux debian.

i use preprocessor directives:

#ifndef vector_hh //or matrix_hh etc.  #define vector_hh    #include <cmath>    //class body      #endif`

good practice define generic header file, can include necessary header files @ one, along header guards.

consider example common-hdr.h wherein declare

#ifndef common-hdr_hh #include <cmath> #include "vector.h" #include "matrix.h"  // other common files  #endif 

now free include common-hdr.h files.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -