Add a new constructor to ParseTree, and make the compCount variable mutable.

This commit is contained in:
Username404 2021-03-18 13:33:36 +01:00
parent 259398f2a3
commit 28175f2d96
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1

View File

@ -11,7 +11,7 @@ class ParseComponent {};
struct ParseTree: public ParseComponent {
private:
unsigned int compCount = 0;
mutable unsigned int compCount = 0;
protected:
vector<ParseComponent> subComponents;
public:
@ -20,6 +20,8 @@ public:
void add(const ParseComponent& component) { subComponents.push_back(component); ++compCount; };
void addAll(const vector<ParseComponent>& 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<ParseComponent>& elements): subComponents() { addAll(elements); }
ParseTree(): subComponents() {};
~ParseTree() = default;
};