From cec77c0a804b9c9924f775b67c780343dc79bbb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 17 Jul 2020 15:50:21 +0200 Subject: [PATCH] SceneGraph: remove constructor signature requirements in addChild(). It now calls setParent() afterwards instead of requiring the last constructor parameter to be a parent pointer. --- doc/changelog.dox | 6 ++++++ src/Magnum/SceneGraph/Object.h | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 4e175fe26..551ce784d 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -137,6 +137,12 @@ See also: @ref Corrade::Containers::ArrayView are now removed. This should have a significant positive effect on compile times of code using the @ref GL, @ref Audio, @ref Trade and @ref Text librariess +- @ref SceneGraph::Object:addChild() no longer requires the type constructor + to have the last parameter a parent object object pointer, as that was + quite limiting. Instead it's calling @ref SceneGraph::Object::setParent() + afterwards. This can cause compilation breakages in case the type + constructor has the parent parameter non-optional, pass the parent + explicitly in that case. @section changelog-2020-06 2020.06 diff --git a/src/Magnum/SceneGraph/Object.h b/src/Magnum/SceneGraph/Object.h index 80a51cb69..cb8c9389b 100644 --- a/src/Magnum/SceneGraph/Object.h +++ b/src/Magnum/SceneGraph/Object.h @@ -195,10 +195,13 @@ template class Object: public AbstractObject(args...)` is equivalent to - * `new MyObject{args..., &object}`. + * `new MyObject{args...}` followed by an appropriate @ref setParent() + * call. */ template T& addChild(Args&&... args) { - return *(new T{std::forward(args)..., this}); + T* child = new T{std::forward(args)...}; + child->setParent(this); + return *child; } /**