fork download
  1. #include <iostream>
  2. #include <list>
  3. using namespace std;
  4.  
  5. class MyList: public list<void*>
  6. {
  7. public:
  8. MyList()
  9. {
  10. cout << "class MyList init"<< endl;
  11. }
  12. void f(){ cout<<"in MyList::f()"<<endl;}
  13. };
  14.  
  15. template<class _T>
  16. class Trash
  17. {
  18. public:
  19. static MyList m_trash;
  20. public:
  21. Trash()
  22. {
  23. cout << "class Trash init" << endl;
  24. }
  25.  
  26. static void Init()
  27. {
  28. cout << "Trash init data" << endl;
  29. //m_trash.push_back(NULL); //error
  30. m_trash.f(); //ok
  31. }
  32. static MyList& GetTrash() { return m_trash; }
  33. };
  34.  
  35. template<class _T>
  36. MyList Trash<_T>::m_trash;
  37.  
  38. class Conf
  39. {
  40. public:
  41. Conf()
  42. {
  43. cout << "class Conf Init" << endl;
  44.  
  45. Trash<void*>::Init();
  46. }
  47.  
  48. ~Conf()
  49. {
  50. cout << "class Conf Del" << endl;
  51. }
  52. };
  53.  
  54. static Conf g_conf;
  55.  
  56. ///////////////////////
  57.  
  58. int main(int argc, char* argv[])
  59. {
  60. return 0;
  61. }
Success #stdin #stdout 0.01s 2680KB
stdin
Standard input is empty
stdout
class Conf Init
Trash init data
in MyList::f()
class MyList init
class Conf Del