From 28175f2d96222f18e9125dc226f14d2a07eebe62 Mon Sep 17 00:00:00 2001 From: Username404 Date: Thu, 18 Mar 2021 13:33:36 +0100 Subject: [PATCH] Add a new constructor to ParseTree, and make the compCount variable mutable. --- src/headers/parsing/ParseComponents.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/headers/parsing/ParseComponents.hpp b/src/headers/parsing/ParseComponents.hpp index 9770e0f..d385c1e 100644 --- a/src/headers/parsing/ParseComponents.hpp +++ b/src/headers/parsing/ParseComponents.hpp @@ -11,7 +11,7 @@ class ParseComponent {}; struct ParseTree: public ParseComponent { private: - unsigned int compCount = 0; + mutable unsigned int compCount = 0; protected: vector subComponents; public: @@ -20,6 +20,8 @@ public: void add(const ParseComponent& component) { subComponents.push_back(component); ++compCount; }; void addAll(const vector& components) { for (const auto& comp: components) add(comp); } void operator<<(const ParseComponent& component) { this->add(component); } + explicit ParseTree(const ParseComponent& element): subComponents() { *this << element; } + ParseTree(const initializer_list& elements): subComponents() { addAll(elements); } ParseTree(): subComponents() {}; ~ParseTree() = default; };