GNOME Bugzilla – Bug 138266
Gtk::Main as a singleton and examples are confusing
Last modified: 2004-12-22 21:47:04 UTC
The examples in the documentation show the declaration of an instance of Gtk::Main inside main() such as: Gtk::Main kit(argc, argv); Such a declaration led me to believe that more than one could be instantiated. I believe I read somewhere that Gtk::Main is a singleton and so this isn't allowed. Am I correct, or am I misremembering? If I am correct, why are instances allowed to be created like this instead of something like the below code that makes it clear that it's a singleton. Am I just misunderstanding something? --- Header file --- class Main { public: Main* getInstance(int& argc, char**& argv, bool set_locale=true); private: Main(int& argc, char**& argv, bool set_locale = true); Main* s_instance; } --- Code file --- Main * Main::s_instance = NULL; Main* Main::getInstance(int& argc, char**& argv, bool set_locale=true) { if (s_instance == NULL) s_instance = new Main(argc, argv, set_locale); return s_instance; }
I don't think it's worth making the syntax so awkward because it's used so often. I'm not also sure that you can't have 2. I think you can have 2 Glib::Mains.
Maybe it should be a bit more like Glib::Main - feel free to try patching that for the future. Closing because it's not really a problem and we can't change it any time soon anyway.