#include #include #include using namespace hgl; class Folder { std::string path; public: Folder() { path.clear(); } ~Folder() { std::cout<<"~Folder(\""< { public: using TreeNode::TreeNode; void OnAttachParent(TreeBaseNode *node) override { TreeNode::OnAttachParent(node); TreeNode *pn=(TreeNode *)node; std::cout<<(*pn)->GetPath()<<"\\"<<(*this)->GetPath()<::OnDetachParent(node); TreeNode *pn=(TreeNode *)node; std::cout<<"remove "<<(*this)->GetPath()<<" from "<<(*pn)->GetPath()<; FolderManager manager; auto *root=manager.Create(); (*root)->SetPath("root"); { auto *win=manager.Create(); (*win)->SetPath("win"); root->AttachChild(win); } { auto *linux=manager.Create(); (*linux)->SetPath("linux"); root->AttachChild(linux); delete linux; //手动释放 } //自动释放到可以了,但是释放顺序需要处理下 }