In this code :
#include <iostream>
using namespace std;
class Singleton{
private:
Singleton(){}
public:
static Singleton* getInstance();
void myFunction(){
cout<<"\nmyFunction() called..";
}
};
Singleton* Singleton :: getInstance(){
static Singleton* obj = NULL;
if(obj == NULL){
cout<<"\nCreating new instance...";
obj = new Singleton();
cout<<"\nReturning instance...";
}
else{
cout<<"\nan old instance already exists...";
cout<<"\nReturning existing instance...";
}
return obj;
}
int main(){
Singleton* myobj = Singleton :: getInstance();
myobj->myFunction();
Singleton* myobj2 = Singleton :: getInstance();
myobj2->myFunction();
}
How many times does this line:
static Singleton* obj = NULL;
execute?
Thnk you.