Code:
Hi,
Thanks for the reply!
I have followed the approach as per your suggestion and have come up with few doubts. Please correct me if i am wrong in any step.
Find my sample code below:
sample.hpp:
class sample;
//extern sample* singleton_object;
sample* instance();
class sample{
public:
int i;
private:
//sample();
};
sample.cpp:
#include "sample.hpp"
sample* singleton_object = new sample;
sample* instance(){return singleton_object;}
Here are the doubts:
i> Can i pl know what is the intended use of extern in your suggestion?
Because even without using extern my code works fine.
ii> Also the constructor is not private in this approach. so, how the class can be made singleton?
Please help me out!
Awaiting for your reply..