C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 1)
1.
Which of the following type of class allows only one object of it to be created?
Discussion:
104 comments Page 1 of 11.
Deep said:
1 decade ago
A class whose number of instances that can be instantiated is limited to one is called a singleton class. Thus, at any given time only one instance can exist, no more.
The singleton design pattern is used whenever the design requires only one instance of a class. Some examples:.
Application classes. There should only be one application class. (Note: Please bear in mind, MFC class 'CWinApp' is not implemented as a singleton class).
Logger classes. For logging purposes of an application there is usually one logger instance required.
The singleton design pattern is used whenever the design requires only one instance of a class. Some examples:.
Application classes. There should only be one application class. (Note: Please bear in mind, MFC class 'CWinApp' is not implemented as a singleton class).
Logger classes. For logging purposes of an application there is usually one logger instance required.
Prem Survase said:
1 decade ago
I can't understand properly concept of Singleton class. ?
Padmanaban said:
1 decade ago
I can't get your definition. Can you make me understand easier?
Pankaj said:
1 decade ago
Tell me also what is singleton class?
Rakesh Sharma said:
1 decade ago
Write the use of singleton class in a program in easy to understand language.
Sneha said:
1 decade ago
How to make singleton class?
Rajkiran said:
1 decade ago
A class whose number of instances that can be instantiated is limited to one is called a singleton class. Thus, at any given time only one instance can exist, no more.
Prasanth said:
1 decade ago
Write a simple exemples in Singleton class?
Sanjaya said:
1 decade ago
class A
{
private:
static A* m_objA;
A(){}; //note constructor is private
public:
~A();
A* GetInstance()
{
if(m_objA)
{
return m_objA;
}
else
{
m_objA = new A();
return m_objA;
}
}
};
{
private:
static A* m_objA;
A(){}; //note constructor is private
public:
~A();
A* GetInstance()
{
if(m_objA)
{
return m_objA;
}
else
{
m_objA = new A();
return m_objA;
}
}
};
Deepi said:
1 decade ago
What is the use of singleton class?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers