mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-01 18:34:50 +00:00
Use a reference instead of a pointer.
The argument is mandatory, so use a reference. This updates get_parent.
This commit is contained in:
parent
8e9d602e88
commit
89c2a251f1
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user