-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleClass.cc
39 lines (37 loc) · 913 Bytes
/
SimpleClass.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
#include <iostream>
class SimpleClass {
public:
SimpleClass(char *n, int v) {
std::cout << " " << n << ".SimpleClass("
<< n << ", " << v << ")" << std::endl;
name = n;
value = v;
}
~SimpleClass() {
std::cout << " " << name << ".~SimpleClass()" << std::endl;
}
void changeValue(int v) {
std::cout << " " << name << ".changeValue(" << v << ")" << std::endl;
value = v;
}
int readValue() {
std::cout << " " << name << ".readValue()" << std::endl;
return value;
}
int copy(SimpleClass &sc) {
std::cout << " " << name << ".copy(" << sc.name << ")" << std::endl;
value = sc.value;
}
private:
char *name;
int value;
};
int main(int argc, char **argv) {
SimpleClass x("x", 12);
SimpleClass y("y", 14);
x.copy(y);
std::cout << x.readValue() << std::endl;
y.changeValue(10);
std::cout << y.readValue() << std::endl;
return 0;
}