I wonder what is the difference between the two codes I wrote below.

        ...
        using namespace nana;

        form fm;

        // This one works
        label lb { fm, rectangle{ 10, 10, 100, 100 } };
        lb.caption("caption").bgcolor(colors::azure);

        // This one doesn't work
        label( fm, rectangle( 10, 10, 100, 100 ) )
            .caption("caption")
            .bgcolor(colors::azure);
        ...

I think the two codes are identical.

I wonder what is the difference between the two codes I wrote below. ```` ... using namespace nana; form fm; // This one works label lb { fm, rectangle{ 10, 10, 100, 100 } }; lb.caption("caption").bgcolor(colors::azure); // This one doesn't work label( fm, rectangle( 10, 10, 100, 100 ) ) .caption("caption") .bgcolor(colors::azure); ... ```` I think the two codes are identical.

Why identical? This is basic c++: the unmaned c++ object is destroyed inmediatelly. Declare it as named object or member of a class. If really really need, keep it alive with a unique_ptr.

Why identical? This is basic c++: the unmaned c++ object is destroyed inmediatelly. Declare it as named object or member of a class. If really really need, keep it alive with a unique_ptr.

In using any GUI framework I think it is important to establish a standard way to manage the lifetime of the widgets. There are several different ways to do this and the details will depend on which framework you like to use, but if you always use the same way then you will save enormous amounts of debugging effort.

Here is what I like to do for nana. To create, manage and cleanly free a widget in a form:

Class myForm : public nana::form
{
public:
    myForm();
private:
    nana:widget_type myWidget;
};

myForm::myForm()
 : myWidget( *this )
{
    myWidget.caption(“Hi”);
    myWidget.move( 100, 100, 50, 30 );
}
In using any GUI framework I think it is important to establish a standard way to manage the lifetime of the widgets. There are several different ways to do this and the details will depend on which framework you like to use, but if you always use the same way then you will save enormous amounts of debugging effort. Here is what I like to do for nana. To create, manage and cleanly free a widget in a form: ```` Class myForm : public nana::form { public: myForm(); private: nana:widget_type myWidget; }; myForm::myForm() : myWidget( *this ) { myWidget.caption(“Hi”); myWidget.move( 100, 100, 50, 30 ); } ````
28
views
2
replies
4
followers
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft