c++ - init_priority attribute on variables in static libs -
this new question after long rant. problem here is, have global vector<base*> vobjs
in main application , got derived obj
s in each static lib linked application. if specify vobjs
have init_priority of 101 , each obj
in static libs have say... 1000, guaranteed vobjs
constructor called before obj
s in static libs? help.
let me echo other responses might want reconsider using globals this. 1 possible (and i'm sure still flawed) improvement @ least removes need init priority.
instead of using global vector
, create function returns reference static local. c++ rules make sure function static local initialized @ latest first use, don't have worry vector not being initialized.
vector<libinfo*>& get_gvlibinfo() { vector<libinfo*> gvlibinfo; return gvlibinfo; }
then registration looks like:
vector<libinfo*>& get_gvlibinfo(); void reglib() { get_gvlibinfo().push_back(this); }
Comments
Post a Comment