-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.cpp
More file actions
28 lines (23 loc) · 695 Bytes
/
Copy pathshared.cpp
File metadata and controls
28 lines (23 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <memory>
#include <vector>
class DAGNode {
// using ptr_type = std::shared_ptr<DAGNode>;
using ptr_type = DAGNode*;
std::vector<ptr_type> children;
public:
ptr_type new_child() {
// children.push_back(std::make_shared<DAGNode>());
children.push_back(new DAGNode());
return children.back();
}
void connect_to(ptr_type ptr) { children.push_back(ptr); }
};
int main() {
DAGNode origin;
auto first_child = origin.new_child();
auto second_child = origin.new_child();
auto grandchild = first_child->new_child();
second_child->connect_to(grandchild);
// grandchild->connect_to(second_child);
}