-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom_to.cpp
More file actions
51 lines (29 loc) · 744 Bytes
/
from_to.cpp
File metadata and controls
51 lines (29 loc) · 744 Bytes
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
#include <iostream>
struct to_3 {
double d;
explicit to_3(double d): d(d){}
explicit operator double() const { return d; }
};
struct to_2 {
double d;
explicit to_2(double d): d(d) {}
explicit operator to_3() const { return to_3{d}; }
};
struct to_1 {
double d;
explicit to_1(double d): d(d) {}
explicit operator to_2() const { return to_2{d}; }
};
struct from {
double d;
explicit from(double d): d(d) {}
explicit operator to_1() const { return to_1{d}; }
};
int main() {
from f{2.2};
to_1 t1 = static_cast<to_1>(f);
to_2 t2 = static_cast<to_2>(t1);
to_3 t3 = static_cast<to_3>(t2);
double d = static_cast<double>(t3);
std::cout << d << std::endl;
}