raw pointers -> shared/weak/unique pointers

May 9, 2013 at 3:53 PM
Edited May 9, 2013 at 7:36 PM
I just have got a little idea that could become a major breaking change.

When I saw at form/widget constructors, I realized that first parameter initializes
internal pointer.If it's true,why don't you use shared/weak/unique pointers instead?

And since widgets have not value semanic and its' lifetime often shouldn't depend of current scope,
why don't we allocate it on heap?
May 10, 2013 at 9:42 AM
In fact, it is a handle, we cannot access its members of the object that handle refers to. On the other hand, we should not take care about its lifetime, the handle is just to provide a way to access the widget. So I chose trivial raw pointers to implement it.

The widgets can be allocated on the heap. e.g.
form fm;
std::vector<std::shared_ptr<button> > buttons;
buttons.emplace_back(new button(fm));
Sometimes, a form should be allocated on heap, but we don't make sure when the pointer should be deleted. E.g

A deprecated method looks like this. When the form is closed, delete the object.
void foo()
    form * p = new form;
        delete p;
It is dangerous. A right way is
void foo()
    form & fm = form_loader<form>()(/*specify the parameters for constructor of form here*/);
    //do something for fm here
May 10, 2013 at 10:09 AM
Thank you for explanation,understood.
I just didn't notice that first parameter is nana::gui::window,not nana::gui::widget.
Then all is clear for me.