   static class constructors / destructors
  Don''t bother researching this one unless you have nothing better to do... aka reply if you know allready . ( I don''t want to waste your time if you don''t ).Given a class with a constructor and destructor, called someclass, what exactly happens with the function:void SomeFunction( void ){  static someclass somevar;}  I believe the constructor is called upon first function call... and then the destructor on program termination. Anyone care to confirm/correct me on this? much thanks . 
  Write the program and try it!  I think it will call the contructor on declaration and call the destructor when the program end.  Isnt that the life of a static member?   [edited by - brain21 on August 1, 2003 5:29:59 PM];  This is correct.  Funny, I verified this last night with the debugger (it's tricky because you can't necessarily print to cout since cout is also destroyed at the same time).I did this in combination with a class that has a private constructor and destructor and made the SomeFunction a friend to the class (a cheap way to do a singleton).  Alas, once you're outside SomeFunction you no longer can reference that object...   [edited by - rypyr on August 1, 2003 5:35:22 PM];quote:Original post by brain21  Write the program and try it!  I think it will call the contructor on declaration and call the destructor when the program end.  Isnt that the life of a static member?   [edited by - brain21 on August 1, 2003 5:29:59 PM]I was just checking if someone else knew off the top of their head... blahrg . Testing it out was my next step... but since no one''s replied ill post my findings:The constructor will indeed be called upon first reaching the static var decleration, and the destructor will be called at program termination...just like expected .Test output:Entered Mainmain: calling funcfunc: before static classsclass: constructorfunc: after static classmain: calling func_callfunc: before static classfunc: after static classmain: calling func_callfunc: before static classfunc: after static classmain: exitingsclass: destructor ;quote:Original post by rypyr  This is correct.  Funny, I verified this last night with the debugger (it''s tricky because you can''t necessarily print to cout since cout is also destroyed at the same time).I did this in combination with a class that has a private constructor and destructor and made the SomeFunction a friend to the class (a cheap way to do a singleton).  Alas, once you''re outside SomeFunction you no longer can reference that object...   [edited by - rypyr on August 1, 2003 5:35:22 PM]I guess I just got lucky with my program then... I used cout in the destructor and it worked . ;class Mgr {  std::vector m_Blahs;  Mgr() {}  ~Mgr() {    cout << "In Mgr destructor" << endl;    cout << "Mgr now has " << m_Blahs.size() << " blahs" << endl;    // now clear out m_Blahs...    cout << "Ending Mgr destructor" << endl;  }}  For me, I got the following output at end of program:In Mgr destructorMgr now hasPress any key to continueIt was funny because it''s only when I accessed some member variable within the Mgr class that it wouldn''t print out any more.  I followed it with the debugger and it executed every line though.Regards,Jeff 