C++ Initialize class static data member -


i have class has number of static function perform calculation. however, before calculation, need pass in data initialize of static data members. have init(data) function , clearresource() function should called before , after use of class. there better way of doing that?

for example:

classa(){  static int a;  static init(int b) {     = b;  }  static functiona(){    //perform based on value of a;     switch(a){     }  }  }  int main(){   classa::init(5);   classa::functiona();  } 

thanks

avoid using static member functions : have constructor initialize data , destructor clear resources (see raii). if existing class cannot changed, implement helper class calls init constructor , clearresource destructor.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -