forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex13_17.cpp
48 lines (42 loc) · 788 Bytes
/
ex13_17.cpp
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
//
// ex13_17.cpp
// Exercise 13.17
//
// Created by pezy on 1/15/15.
// Copyright (c) 2015 pezy. All rights reserved.
//
// Write versions of numbered and f corresponding to the previous three exercises
// and check whether you correctly predicted the output.
//
// See 13.14, 13.15, 13.16
#include <iostream>
class numbered {
public:
// 13.14
numbered() {
static int unique = 10;
mysn = unique++;
}
// 13.15
numbered(const numbered& n) {
mysn = n.mysn+1;
}
int mysn;
};
// 13.16
void f(const numbered &s) {
std::cout << s.mysn << std::endl;
}
int main()
{
numbered a, b = a, c = b;
f(a);
f(b);
f(c);
}
// output
// 10 11 10
// 10 -> 12 -> 11
// 10 13 12
// ^ ^ ^
// 14 15 16