What is singleton class in c++?



What is singleton class in c++?..

Answer / Gayatri Saini

The Singleton design pattern restricts the instantiation of a class to a single instance. In C++, this can be achieved by making the constructor private and providing a static member function that returns the instance of the class if it already exists or creates and stores one.n"singleton_class".h {"public:":n static singleton_class& get_instance();nprivate:n singleton_class(const singleton_class&) = delete; // prevent copyingn singleton_class& operator=(const singleton_class&) = delete;n static singleton_class instance;n ~singleton_class() {"}n}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

Differentiate between a deep copy and a shallow copy?

1 Answers  


What is Object Oriented programming.what is the difference between C++ and C?

8 Answers   Infosys,


Tell me an example where stacks are useful?

1 Answers  


Explain the use of this pointer?

1 Answers  


Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.

1 Answers   TCS,


Differentiate between a copy constructor and an overloaded assignment operator.

1 Answers  


Write some differences between an external iterator and an internal iterator?

1 Answers  


Why c++ is the best language?

1 Answers  


write infinite loop in C++ which does not use any variable or constant?

3 Answers  


What does count ++ do in c++?

1 Answers  


Can a built-in function be recursive?

1 Answers  


can any one help to find a specific string between html tags which is changed to a sting.. weather.html looks (for location) is <location>somewhere</location> #include <iostream> #include <fstream> #include <string> using namespace std; string find_field(string myPage,string); int main (void) { string page, line, location, temperature; ifstream inputFile("weather.xml"); while(getline(inputFile, line)) { page.append(line); line.erase(); } // Now page is a string that contains the whole xml page // Here you need to write something that finds and // extracts location and temperature from the XML // data in the string page and stores them in // the strings location and temperature respectively location=find_field(page,"location"); temperature=find_field(page,"temp_c"); cout << "Location: "<<location << endl; cout << "Temperature: " << temperature << endl; system("pause"); } string find_field(string myPage,string find_string){ int temp=myPage.find(find_string); if(temp!=string::npos) { cout << "Match found at " << temp << endl; } return "found?"; } ///

1 Answers  


Categories