mirror of
https://github.com/JakubVojvoda/design-patterns-cpp.git
synced 2025-12-17 21:04:36 +03:00
fix Singleton pattern
This commit is contained in:
@@ -28,19 +28,19 @@ public:
|
|||||||
std::cout << "This is Singleton." << std::endl;
|
std::cout << "This is Singleton." << std::endl;
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Singleton() {}
|
||||||
static Singleton *instance;
|
static Singleton *instance;
|
||||||
// ...
|
// ...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Singleton* Singleton::instance = nullptr;
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Singleton singleton;
|
Singleton::get()->tell();
|
||||||
singleton.tell();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user