单例模式
#include <iostream>
using namespace std;
class Person
{
private:
string id;
string hometown;
static Person *ptr;
public:
static Person* create()
{
if(ptr == NULL)
{
ptr = new Person;
}
return ptr;
}
};
Person* Person::ptr = NULL;
int main()
{
Person *p = Person::create();
system("pause");
return 0;
}