-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ex15_26_Quote.h
72 lines (55 loc) · 1.8 KB
/
ex15_26_Quote.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
=================================================================================
C++ Primer 5th Exercise Answer Source Code
Copyright (C) 2014-2015 https://github.com/pezy/Cpp-Primer
Quote class
1. define copy-control members to do the same job as the synthesized versions.
2. Print function name to trace the running.
If you have questions, try to connect with me: pezy<urbancpz@gmail.com>
=================================================================================
*/
#ifndef CP5_EX15_26_QUOTE_H
#define CP5_EX15_26_QUOTE_H
#include <string>
#include <iostream>
namespace EX26 {
using std::string;
using std::cout; using std::endl;
class Quote {
public:
Quote() {
cout << "Quote Constructor" << endl;
}
Quote(const string &b, double p) : bookNo(b), price(p) {
cout << "Quote Constructor taking two parameters" << endl;
}
Quote(const Quote &rhs) : bookNo(rhs.bookNo), price(rhs.price) {
cout << "Quote Copy Constructor" << endl;
}
Quote& operator=(const Quote &rhs) {
cout << "Quote Copy assignment operator" << endl;
price = rhs.price;
bookNo = rhs.bookNo;
return *this;
}
Quote(Quote &&rhs) noexcept : bookNo(std::move(rhs.bookNo)), price(std::move(rhs.price)) {
cout << "Quote Move Constructor" << endl;
}
Quote& operator=(Quote &&rhs) noexcept {
cout << "Quote Move assignment operator" << endl;
bookNo = std::move(rhs.bookNo);
price = std::move(rhs.price);
return *this;
}
virtual ~Quote() {
cout << "Quote Destructor" << endl;
}
string isbn() const { return bookNo; }
virtual double net_price(size_t n) const { return n * price; }
private:
string bookNo;
protected:
double price = 0.0;
};
}
#endif //CP_EX15_26_QUOTE_H