Student.h

1: 
#ifndef __SINGLETON_H__
#define __SINGLETON_H__
   4:  
#include <memory>
   6:  
class T>
class SingleT
   9: {
public:
static T * Instance()
  12:     {
if (!p)
  14:         {
new T;
  16:         }
  17:  
return p;
  19:     }
  20:  
void Create()
  22:     {
if (!p)
  24:         {
new T;
  26:         }
  27:     }
  28:  
void Destroy()
  30:     {
if (p)
  32:         {
delete p;
  34:             p = NULL;
  35:         }
  36:     }
  37:  
static T * Get()
  39:     {
return p;
  41:     }
  42:  
void Reset()
  44:     {
  45:         Destroy();
  46:         Create();
  47:     }
  48:  
protected:
static T * p;
  51: };
  52:  
class T>
  54: T * SingleT<T>::p = NULL;
  55:  
#endif
  57:  

相关文章:

  • 2021-11-19
  • 2021-06-20
  • 2021-06-17
  • 2022-01-27
  • 2022-01-17
猜你喜欢
  • 2021-09-19
  • 2022-12-23
  • 2021-09-02
  • 2022-01-10
  • 2021-07-18
相关资源
相似解决方案