-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAInteger.cc
44 lines (37 loc) · 899 Bytes
/
AInteger.cc
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
#include <iostream>
using namespace std;
class AInteger {
public:
AInteger() {
value = 0;
}
AInteger(int i) {
value = i;
}
AInteger(const AInteger &ai) {
value = ai.value;
std::cout << " copy" << std::endl;
}
// As we have seen, this operator is also an expression.
// To be consistent, we have to return a reference to the
// result of the assignment, which is the object itself
AInteger &operator = (const AInteger &ai) {
value = ai.value;
std::cout << " =" << std::endl;
return *this;
}
// virtual ~AInteger();
private:
int value;
};
void nothing(AInteger a, AInteger b, AInteger c) { }
int main(int argc, char **argv) {
AInteger i(14), j;
std::cout << "AInteger k = i;" << std::endl;
AInteger k = i;
std::cout << "k = i;" << std::endl;
j = i;
std::cout << "nothing(i);" << std::endl;
nothing(i, j, k);
return 0;
}