cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Singleton
Singleton
Apr 7, 2016 at 11:13am UTC
sharmila oruganti
(1)
Hi ,
class Example{
private:
void Example()
{
cout <<" constructor ";
}
public:
static Example* obj;
static Example* instantiate()
{
if(!obj)
obj = new Example();
return obj;
}
Example* oneMore()
{
return new Example();
}
};
main()
{
Example* ptr= Example::instantiate();
ptr->oneMore();
}
In the above class i want to maintain singleton behavior .By call oneMore() it will call the constructor of Example() and breaks singleton behavior. So how to over come this problem .
Apr 7, 2016 at 11:33am UTC
Moschops
(7244)
Delete the function
oneMore()
Topic archived. No new replies allowed.