From 6522a887f9decbea82685b3083cd319a56ef00d2 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Sat, 18 Jan 2025 00:11:00 +0100 Subject: [PATCH] fix: AddChild had wrong implementation and enable_shared_from_this was not correctly inherited --- src/objects/base/instance.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/objects/base/instance.h b/src/objects/base/instance.h index e979184..865ccb5 100644 --- a/src/objects/base/instance.h +++ b/src/objects/base/instance.h @@ -12,7 +12,10 @@ struct InstanceType { }; // Base class for all instances in the data model -class Instance : std::enable_shared_from_this { + // Note: enable_shared_from_this HAS to be public or else its field will not be populated + // Maybe this could be replaced with a friendship? But that seems unnecessary. + // https://stackoverflow.com/q/56415222/16255372 +class Instance : public std::enable_shared_from_this { private: std::optional> parent; std::vector> children; @@ -30,7 +33,7 @@ public: inline const std::vector> GetChildren() { return children; } // Utility functions - inline void AddChild(std::shared_ptr object) { children.push_back(object); } + inline void AddChild(std::shared_ptr object) { object->SetParent(this->shared_from_this()); } }; typedef std::shared_ptr InstanceRef;