25 lines
441 B
C++
25 lines
441 B
C++
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
class Singleton {
|
|
Singleton() {}
|
|
public:
|
|
// Copy construction and assignment is disabled;
|
|
Singleton(Singleton &other) = delete;
|
|
void operator=(const Singleton &) = delete;
|
|
|
|
static Singleton& get_instance() {
|
|
static Singleton s;
|
|
return s;
|
|
}
|
|
|
|
void f() {
|
|
cout << "Singleton::f()" << endl;
|
|
}
|
|
};
|
|
|
|
int main() {
|
|
Singleton::get_instance().f();
|
|
}
|