@frek,
I think by this:
Now do you still need our widget to be parented? Or what's/re the advantage(s), (if any) of that parent-child relation in this case?
|
The operating systems implementing GUI have parent/child relationships in the objects created using a C API (in most that I know). There are, along the way, a range of GUI objects which are acquired, like device contexts, icons, brushes, pens...these belong to the operating system. They are not allocated as memory, they are acquired in a way more analogous to a file handle. What your application receives from such a resource is usually a handle (a numeric identifier, not a memory location).
This is what RAII is aimed at helping to control, but it is not a smart pointer required, it is more abstract representation, something along the lines of the way that iostream will represent a file, when it is opened.
The GUI's relationships (parent/child, or the objects like contexts that may be acquired upon them) must be modeled by a C++ framework in order to assist in controlling them.
It would, therefore, be the RAII implementation in that framework which controls the acquisition and release of those related resources.
The smart pointers would be limited to those C++ objects allocated within the framework.
It is common (perhaps unfortunately) that when using frameworks (not just GUI, but physics engines, game engines, database systems, math libraries) that those frameworks may employ their own version of memory management. As long as it works, there's no reason to reconsider their design. Some may have their own smart pointers for memory, and may well exhibit a "smart pointer like" behavior relative to representative object classes like brush, dc, pen, window (panel), etc.