Use a reference instead of a pointer.

The argument is mandatory, so use a reference.

This updates get_parent.
This commit is contained in:
Mark de Wever 2013-06-01 15:03:54 +02:00
parent 8e9d602e88
commit 89c2a251f1
2 changed files with 7 additions and 6 deletions

View File

@ -30,17 +30,18 @@ namespace gui2 {
*
* @returns The parent widget.
*/
template<class T> T* get_parent(twidget* widget)
template<class T> T& get_parent(twidget& widget)
{
T* result;
twidget* w = &widget;
do {
widget = widget->parent();
result = dynamic_cast<T*>(widget);
w = w->parent();
result = dynamic_cast<T*>(w);
} while (widget && !result);
} while (w && !result);
assert(result);
return result;
return *result;
}
/**

View File

@ -43,7 +43,7 @@ REGISTER_WIDGET3(tlistbox_definition, horizontal_listbox, _4)
void callback_list_item_clicked(twidget& caller)
{
get_parent<tlistbox>(&caller)->list_item_clicked(caller);
get_parent<tlistbox>(caller).list_item_clicked(caller);
}
} // namespace