-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrvalue.cpp
More file actions
58 lines (44 loc) · 742 Bytes
/
rvalue.cpp
File metadata and controls
58 lines (44 loc) · 742 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <memory>
#include <string>
using namespace std;
class str
{
public:
str(string s="def string")
{
cout << "def ctor is called" << endl;
this->s = s;
}
str(str const& rhs)
{
cout << "copy ctor is called" << endl;
if (this != &rhs)
s = rhs.s;
}
str& operator=(str const& rhs)
{
cout << "assign operator is called" << endl;
if (this != &rhs) s = rhs.s;
return *this;
}
str(str && s)
{
cout << "move ctor is called" << endl;
}
string s;
};
class value
{
public:
value(): s("leech") { }
str&& get_value() { return move(s); }
private:
str s;
};
int main(int argc, char *argv[])
{
value v;
cout << v.get_value().s;
return 0;
}