shared children disappear
This commit is contained in:
+30
-14
@@ -1,4 +1,4 @@
|
||||
#include "nodes/SimpleNode.h"
|
||||
#include "nodes/SimpleNode.h" // Путь изменен
|
||||
#include <iostream>
|
||||
|
||||
void printTree(const NodePtr& startNode, int indent = 0) {
|
||||
@@ -12,24 +12,40 @@ void printTree(const NodePtr& startNode, int indent = 0) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto root = SimpleNode::create("Root");
|
||||
auto child1 = SimpleNode::create("Child1");
|
||||
auto child2 = SimpleNode::create("Child2");
|
||||
std::cout << "Entering main scope...\n\n";
|
||||
|
||||
root->linkChild(child1);
|
||||
root->linkChild(child2);
|
||||
// Начало новой области видимости
|
||||
{
|
||||
auto root = SimpleNode::create("Root");
|
||||
auto child2 = SimpleNode::create("Child2");
|
||||
|
||||
auto subchild = SimpleNode::create("SubChild");
|
||||
child1->linkChild(subchild);
|
||||
root->linkChild(child2);
|
||||
|
||||
std::cout << "Initial tree:\n";
|
||||
printTree(root);
|
||||
{
|
||||
auto child1 = SimpleNode::create("Child1");
|
||||
root->linkChild(child1);
|
||||
auto subchild = SimpleNode::create("SubChild");
|
||||
child1->linkChild(subchild);
|
||||
auto child3 = SimpleNode::create("Child3");
|
||||
root->linkChild(child3);
|
||||
auto subchild2 = SimpleNode::create("SubChild2");
|
||||
child3->linkChild(subchild2);
|
||||
|
||||
std::cout << "\nUnlinking Child1...\n";
|
||||
child1->unlinkParent();
|
||||
std::cout << "Initial tree:\n";
|
||||
printTree(root);
|
||||
|
||||
std::cout << "\nFinal tree:\n";
|
||||
printTree(root);
|
||||
std::cout << "\nUnlinking Child1...\n";
|
||||
child1->unlinkParent();
|
||||
std::cout << "\nTree after unlink:\n";
|
||||
printTree(root);
|
||||
}
|
||||
|
||||
std::cout << "\nTree after scope out:\n";
|
||||
printTree(root);
|
||||
|
||||
} // <--- КОНЕЦ ОБЛАСТИ ВИДИМОСТИ
|
||||
|
||||
std::cout << "\nExited main scope. All smart pointers destroyed.\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user