-
Notifications
You must be signed in to change notification settings - Fork 1
/
E53.h
56 lines (45 loc) · 1 KB
/
E53.h
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
#ifndef E53_H
#define E53_H
#include <string>
using std::string;
#include <iostream>
using std::cout;
using std::endl;
class HasPtr{
public:
friend void swap(HasPtr&, HasPtr&);
HasPtr(const string& s);
HasPtr(const HasPtr&);
HasPtr(HasPtr&&) noexcept;
HasPtr& operator=(const HasPtr &);
HasPtr& operator=(HasPtr &&) noexcept;
// HasPtr& operator=(HasPtr);
~HasPtr();
private:
string *ps;
int i;
};
inline void swap(HasPtr& lhs, HasPtr& rhs){
using std::swap;
swap(lhs.ps, rhs.ps);
swap(lhs.i, rhs.i);
cout << "call swap" << endl;
}
HasPtr::HasPtr(const string& s):ps(new string(s)), i(0) {
cout << "call constructor" << endl;
}
HasPtr::HasPtr(const HasPtr& hp):ps(new string(*hp.ps)), i(hp.i){
cout << "call copy constructor" << endl;
}
HasPtr::HasPtr(HasPtr &&p) noexcept : ps(p.ps), i(p.i){
cout << "call move constructor" << endl;
}
// HasPtr& HasPtr::operator=(HasPtr rhs){
// swap(*this,rhs);
// return *this;
// }
HasPtr::~HasPtr(){
cout << "call destructor" << endl;
delete ps;
}
#endif