-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.cpp
More file actions
42 lines (33 loc) · 673 Bytes
/
main.cpp
File metadata and controls
42 lines (33 loc) · 673 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
class Node
{
public:
Node(std::string const& name)
: m_name(name)
{}
~Node() = default;
std::string const& GetName() {
return m_name;
}
Node* GetNext() {
return m_next;
}
void SetNext(Node* nextNode) {
auto lm = [this, nextNode]() {
m_next = nextNode;
};
lm();
}
private:
Node* m_next = nullptr;
std::string m_name;
};
int main() {
Node n1("Node # 1");
Node n2("Node # 2");
n1.SetNext(&n2);
assert(n1.GetNext()); // true
std::cout << n1.GetNext()->GetName() << std::endl; // Node # 2
return 0;
}