A
Allen
class MyClass
{
private:
MyClass(void);
public:
static MyClass* pInstance;
static MyClass& GetInstance();
virtual ~MyClass();
public:
int Add(int op1, int op2);
};
I can use these ways:
c1. MyClass& objRef = MyClass::GetInstance();
c2. MyClass obj = MyClass::GetInstance();
The c1 is easy to understand, it uses a reference objRef assignment.
While the c2 is difficult to understand to me.
The constructor of MyClass is private. And C2 uses value assignment.
Who can explaint it?
Thank you!
{
private:
MyClass(void);
public:
static MyClass* pInstance;
static MyClass& GetInstance();
virtual ~MyClass();
public:
int Add(int op1, int op2);
};
I can use these ways:
c1. MyClass& objRef = MyClass::GetInstance();
c2. MyClass obj = MyClass::GetInstance();
The c1 is easy to understand, it uses a reference objRef assignment.
While the c2 is difficult to understand to me.
The constructor of MyClass is private. And C2 uses value assignment.
Who can explaint it?
Thank you!