14 Oct
2022
14 Oct
'22
12:27 a.m.
class HelloWorldNode { public: HelloWorldNode(HelloWorldNode * parent, string data) : parent(parent), data(data) { if (parent) parent.children.add(this); } ~HelloWorldNode() { if (parent) parent.children.erase(this); } void print() { cout << data; for (auto child : children) child.print(); } private: HelloWorldNode * parent; string data; set<HelloWorldNode*> children; }; using HWN = HelloWorldNode; int main() { HWN hello(0, “hello”); HWN space(&hello, “ “); HWN world(&space, “world”); HWN bang(&world, “!”); HWN decorations[] = { HWN(&hello, “\t”), HWN(&world, “~~”), HWN(&bang, “#”) }; hello.print(); }