class Singleton
{
public:
~Singleton() {
std::cout << "destructor called!" << std::endl;
}
Singleton(const Singleton&) = delete;
Singleton& operator=(const Singleton&) = delete;
static Singleton& get_instance() {
static Singleton instance;
return instance;
}
private:
Singleton() {
std::cout << "constructor called!" << std::endl;
}
};
int main(int argc, char* argv[])
{
Singleton& instance_1 = Singleton::get_instance();
Singleton& instance_2 = Singleton::get_instance();
return 0;
}
C++ singleton
最新推荐文章于 2024-10-31 09:04:32 发布