On Tue, Apr 14, 2015 at 6:27 PM, Thiago Macieira <[email protected]> wrote: > On Tuesday 14 April 2015 16:56:19 René J.V. Bertin wrote: > [cut] >> ObjC is so intricately linked to OS X, because from a few quick attempts it >> seems to be perfectly possible to use an ObjC++ wrapper class to extend the >> retain/release scheme to C++ classes. >> >> Is this clear enough? > > Yes, thank you. > > C++ already has that, it's called reference counting. You may have heard we > use it in Qt :-) > > The problem here is that QCoreApplication is not reference counted and we > can't change it without breaking *every* *single* *application*, since this is > what people usually do: > > int main(int argc, char **argv) > { > SomeApplication app(argc, argv); > [rest of the application] > } > > That stack declaration is the problem here. The app object will be destroyed > at the closing brace, whether we want it or not, and there's nothing we can do > to prevent it, delay it or even hook something as it begins. > > We can only catch it half-way through, when the destruction has reached one of > our classes (~QApplication, ~QGuiApplication or ~QCoreApplication), by which > time the virtual table has already changed and it's too late.
C++ idiom with protected destructor enforces heap-allocation of objects and prevents stack allocation. It requires some public destroy() calling "delete this" inside. jm2c Regards, Robert _______________________________________________ Development mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/development
