代码块
头文件
#include <iostream>
class BrowserSetting
{
public :
static BrowserSetting *GetInstance()
{
if (m_Instance == NULL)
{
m_Instance = new BrowserSetting();
}
return m_Instance;
}
static void DestoryInstance()
{
if (m_Instance != NULL)
{
delete m_Instance;
m_Instance = NULL;
}
}
// This is just a operation example
int GetWidth()
{
return m_Width;
}
int GetHeight()
{
return m_Height;
}
void ChangeWidth(int width)
{
m_Width = width;
}
void ChangeHeight(int height)
{
m_Height = height;
}
private:
BrowserSetting()
{
m_Width = 1360;
m_Height = 768;
}
static BrowserSetting *m_Instance;
int m_Width , m_Height;
};
引用
BrowserSetting *BrowserSetting::m_Instance = NULL;
BrowserSetting *b = BrowserSetting::GetInstance();