在此,我试图将单例对象复制到另一个对象。虽然我已经覆盖了 = 运算符,但它给了我一些问题。请帮忙。
class singleTon
{
public:
static singleTon* InitInstance()
{
if(singleTonObjPtr== NULL)
{
singleTonObjPtr = new singleTon;
}
return singleTonObjPtr;
}
singleTon* getObject()
{
return singleTonObjPtr;
}
singleTon(const singleTon& singletonObj)
{
}
void operator =(const singleTon& singletonObj)
{
return;
}
private:
singleTon()
{
i = 50;
singleTonObjPtr = NULL;
}
~singleTon()
{
}
int i;
static singleTon* singleTonObjPtr;
};
singleTon* singleTon::singleTonObjPtr = NULL;
int _tmain(int argc, _TCHAR* argv[])
{
singleTon *singleTOnPtr =NULL;
singleTOnPtr = singleTon::InitInstance();
singleTon *singleTOnPtr2 = singleTOnPtr->getObject();
singleTon obj3 = *singleTon::InitInstance();
}