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 |
Differentiate between a deep copy and a shallow copy?
What is Object Oriented programming.what is the difference between C++ and C?
Tell me an example where stacks are useful?
Explain the use of this pointer?
Give the difference between the type casting and automatic type conversion. Also tell a suitable C++ code to illustrate both.
Differentiate between a copy constructor and an overloaded assignment operator.
Write some differences between an external iterator and an internal iterator?
Why c++ is the best language?
write infinite loop in C++ which does not use any variable or constant?
What does count ++ do in c++?
Can a built-in function be recursive?
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?"; } ///