i want define series of global variables within parametrise() helper function this:
// helper.h namespace settings { extern const unsigned short something; } namespace helper { void parametrise(int, char**); // parametrise command line using boost::program_options } // main.cpp int main( int argc, char** argv) { helper::parametrise(argc, argv); return 0; } // helper.cpp void helper::parametrise(int, char**) { // parse input here const unsigned short settings::something = .. // want }
this code not compile of course, there has way around it.. or not?
you can make writable within translation unit, , have externally const, so:
// helper.h namespace settings { extern const unsigned short& something; } void parametrise(int, char**); // helper.cpp namespace { namespace settings_internal { unsigned short something; }} namespace settings { const unsigned short& = settings_internal::something; } void parametrise(int, char**) { settings_internal::something = 123; }
Comments
Post a Comment