Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.35 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Static and Normal class combined in one class
  2. public ref class TestClass
  3. {      
  4. public:
  5.         TestClass();
  6.         virtual ~TestClass();
  7. protected:              
  8.         Car* m_car;
  9.  
  10. }
  11.        
  12. public ref class TestClass
  13. {
  14. private:
  15.     static  TestClass^  s_test = nullptr ;
  16. public:
  17.     TestClass();
  18.     virtual ~TestClass();
  19.     static TestClass^ Instance();
  20. protected:              
  21.     Car* m_car;
  22. }
  23.        
  24. TestClass staticobj = TestClass::Instance();
  25.        
  26. TestClass normalobj = gcnew TestClass();
  27.        
  28. TestClass ^ TestClass::Instance()
  29. {
  30.     if(s_test == nullptr)
  31.     {
  32.           s_test = gcnew TestClass();
  33.           s_test->m_car = new Car();
  34.  
  35.     }      
  36.     return s_test;
  37. }
  38.        
  39. public ref class SpecialSingletonTestClass: public TestClass
  40.         {
  41.             private:
  42.                 static SpecialSingletonTestClass ^ s_ SpecialSingletonTestClass = nullptr;
  43.              public:
  44.                 SpecialSingletonTestClass ();
  45.                 static SpecialSingletonTestClass ^ Instance();
  46.         };
  47.        
  48. public ref class TestClass
  49.     {
  50.     public:
  51.         TestClass ();
  52.         virtual ~ TestClass ();
  53.         ! TestClass ();
  54. protected:              
  55.          Car* m_car;
  56.  
  57.     }
  58.        
  59. TestClass()
  60. {
  61.     m_car = new Car();
  62. }
  63.  
  64. ~TestClass()
  65. {
  66.     if (m_car)
  67.         delete m_car;
  68.     m_car = NULL;
  69. }
  70.  
  71. !TestClass()
  72. {
  73.     if (m_car)
  74.         delete m_car;
  75.     m_car = NULL;
  76. }