tmp
This commit is contained in:
+36
-36
@@ -2,50 +2,50 @@
|
||||
#include <iostream>
|
||||
|
||||
void printTree(const NodePtr& startNode, int indent = 0) {
|
||||
if (!startNode) return;
|
||||
for (int i = 0; i < indent; ++i) std::cout << " ";
|
||||
std::cout << startNode->name() << "\n";
|
||||
LinkPtr nodeLink = startNode->getLink();
|
||||
for (const auto& childLink : nodeLink->getChildren()) {
|
||||
printTree(childLink->getNode(), indent + 1);
|
||||
}
|
||||
if (!startNode) return;
|
||||
for (int i = 0; i < indent; ++i) std::cout << " ";
|
||||
std::cout << startNode->name() << "\n";
|
||||
LinkPtr nodeLink = startNode->getLink();
|
||||
for (const auto& child : nodeLink->getChildren()) {
|
||||
printTree(child, indent + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Entering main scope...\n\n";
|
||||
|
||||
// Начало новой области видимости
|
||||
{
|
||||
auto root = SimpleNode::create("Root");
|
||||
auto child2 = SimpleNode::create("Child2");
|
||||
|
||||
root->linkChild(child2);
|
||||
std::cout << "Entering main scope...\n\n";
|
||||
|
||||
// Начало новой области видимости
|
||||
{
|
||||
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);
|
||||
auto root = std::make_shared<SimpleNode>("Root");
|
||||
auto child2 = std::make_shared<SimpleNode>("Child2");
|
||||
|
||||
std::cout << "Initial tree:\n";
|
||||
root->linkChild(child2);
|
||||
|
||||
{
|
||||
auto child1 = std::make_shared<SimpleNode>("Child1");
|
||||
root->linkChild(child1);
|
||||
auto subchild = std::make_shared<SimpleNode>("SubChild");
|
||||
child1->linkChild(subchild);
|
||||
auto child3 = std::make_shared<SimpleNode>("Child3");
|
||||
root->linkChild(child3);
|
||||
auto subchild2 = std::make_shared<SimpleNode>("SubChild2");
|
||||
child3->linkChild(subchild2);
|
||||
|
||||
std::cout << "Initial 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 << "\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";
|
||||
|
||||
} // <--- КОНЕЦ ОБЛАСТИ ВИДИМОСТИ
|
||||
|
||||
std::cout << "\nExited main scope. All smart pointers destroyed.\n";
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user