Re: Why isn't the constructor of Gtk::Application public?

Rob Pearce <[email protected]> Tue, 28 Sep 2021 18:26:51 +0100
Newsgroups gmane.comp.gnome.gtkmm
Message-ID <[email protected]>
On 28/09/2021 15:07, [email protected] wrote:
> If the constructor would be public we and the compiler wouldn't have to
> deal with smart pointers:
>
> Gtk::Application app("org.example");
> return app.make_window_and_run<MyWindow>(argc, argv);
>
> The Gtk::Application::create function just passes the argument to the
> constructor and stores the Gtk::Application in a Glib::RefPtr. Is there
> a reason why the constructor isn't public?

At a guess... precisely to prevent you doing what you suggest!

Statically allocated complex class instances are seriously problematic 
in C++ because the order of initialisation and instantiation of "static" 
objects is very poorly defined. There were many places in GTKmm 2.4 
where objects that could be instantiated statically would simply break. 
The correct approach was always to dynamically generate a singleton and 
use that, thus providing a guaranteed order of creation.