When I was learning the singleton pattern, I saw that the constructor is private, so can static class member variables still be initialized with new()?
#include <iostream>
using namespace std;
class A{
public:
static A* getInstance(){
return aa;
}
void setup(){
cout<<"inside setup!"<<endl;
}
private:
static A* aa;
A(){
cout<<"constructor called!"<<endl;
}
};
A* A::aa = new A; // <== How to explain this sentence ???
int main()
{
A* aa1 = A::getInstance();
A* aa2 = A::getInstance();
if(aa1 == aa2)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
cout << "Hello world!"<<endl;
return 0;
}