c++ - Including constants without importing header file -
i have piece of code set take constant integer parameter (dimension of problem), run many different dimensions.
i don't want have change hard-coded dimension every time run, ideally define several dummy header functions just:
#ifndef dim_define_h #define dim_define_h const int dimension = [dimension specific header file]; #endif
then when compiling use whichever header file needed instance like:
g++ dimension_6.h code.cpp
is such thing possible? defining constant in header file , using in file doesn't explicitly import header file?
edit:
my next attempt take main function only, stick along dimension definition in different file, , make copies of that. compilation looks like:
g++ dim_specific_main.cpp lots.cpp more.cpp helpers.cpp
and think it's making through compilation of main now, depend on helper functions defined in helper files. unfortunately when tries compile helper functions needs constant that's defined in main.h , seems have forgotten it.
edit 2: realize i'm trying use variable in places needs known @ compile time, , think linkage happens after compiling, not believe particular approach possible.
const int dimension = the_dimension;
then compile with
g++ -dthe_dimension=6 code.cpp
no header needed.
Comments
Post a Comment