From 72e667b9fd8154683e4f4968870137d75a75481c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 10 Apr 2012 01:33:01 +0200 Subject: [PATCH] Object const-correctness. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Const function shouldn̈́'t return anything with which it would be possible to change object's internal state: * It is possible to get non-constant pointer to itself from parent().children() array, so parent() cannot be const function. * The same applies to scene(). * It is also possible to get non-constant pointer to itself from children()[0].parent(), so children() also cannot be const function. --- src/Object.cpp | 2 +- src/Object.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Object.cpp b/src/Object.cpp index a61097538..55d778e77 100644 --- a/src/Object.cpp +++ b/src/Object.cpp @@ -79,7 +79,7 @@ Object::~Object() { delete *_children.begin(); } -Scene* Object::scene() const { +Scene* Object::scene() { /* Goes up the family tree until it finds object which is parent of itself (that's the scene) */ Object* p = parent(); diff --git a/src/Object.h b/src/Object.h index 257b430f6..cd0302254 100644 --- a/src/Object.h +++ b/src/Object.h @@ -65,13 +65,13 @@ class MAGNUM_EXPORT Object { * @brief %Scene * @return If the object is not assigned to any scene, returns nullptr. */ - Scene* scene() const; + Scene* scene(); /** @brief Parent object */ - inline Object* parent() const { return _parent; } + inline Object* parent() { return _parent; } /** @brief Child objects */ - inline const std::set& children() const { return _children; } + inline const std::set& children() { return _children; } /** @brief Set parent object */ void setParent(Object* parent);