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



On 28/09/2021 15:07, phosit autistici org 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.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]