Compare Pastes
Differences between the pastes
#134205 (05.05.2020 14:29)
and
#134206 (05.05.2020 14:41).
1 | 1 | #include |
2 | 2 | |
3 | 3 | class type_one |
4 | 4 | { |
5 | 5 | }; |
6 | 6 | |
7 | 7 | class type_two |
8 | 8 | { |
9 | 9 | }; |
10 | 10 | |
11 | 11 | class i_one |
12 | 12 | { |
13 | 13 | public: |
14 | 14 | virtual void set (const type_one & val, int id) = 0; |
15 | 15 | }; |
16 | 16 | |
17 | 17 | class i_two |
18 | 18 | { |
19 | 19 | public: |
20 | 20 | virtual void set (const type_two & val) = 0; |
21 | 21 | }; |
22 | 22 | |
23 | 23 | |
24 | 24 | |
25 | 25 | class i_one_two:public i_one, public i_two |
26 | 26 | { |
27 | }; | |
28 | ||
27 | ||
28 | // = = = = = = >>> Вот решение | |
29 | 29 | |
30 | class OneTwo:public i_one_two | |
31 | { | |
32 | public: | |
33 | void set (const type_one & val, int id) | |
34 | { | |
35 | std::cout << "type_one value, id = " << id; | |
36 | } | |
37 | ||
38 | void set (const type_two & val) | |
39 | { | |
40 | std::cout << "type_two value\n"; | |
41 | } | |
42 | }; | |
30 | //public: | |
31 | // virtual void set (const type_one & val, int id) = 0; | |
32 | // virtual void set (const type_two & val) = 0; | |
33 | }; | |
34 | ||
35 | ||
36 | class OneTwo:public i_one_two | |
37 | { | |
38 | public: | |
39 | void set (const type_one & val, int id) | |
40 | { | |
41 | std::cout << "type_one value, id = " << id; | |
42 | } | |
43 | 43 | |
44 | ||
45 | int | |
46 | main () | |
47 | { | |
48 | OneTwo ot; | |
44 | void set (const type_two & val) | |
45 | { | |
46 | std::cout << "type_two value\n"; | |
47 | } | |
48 | }; | |
49 | 49 | |
50 | i_one_two *i12 = &ot; | |
51 | ||
52 | i12->set(type_one (), 111); // error: request for member ‘set’ is ambiguous | |
53 | i12->set(type_two ()); // error: request for member ‘set’ is ambiguous | |
54 | return 0; | |
55 | } | |
56 | ||
57 | //============================== | |
58 | main.cpp: In function ‘int main()’: | |
59 | main.cpp:52:8: error: request for member ‘set’ is ambiguous | |
60 | i12->set(type_one (), 111); | |
61 | ^~~ | |
62 | main.cpp:20:16: note: candidates are: virtual void i_two::set(const type_two&) | |
63 | virtual void set (const type_two & val) = 0; | |
64 | ^~~ | |
65 | main.cpp:14:16: note: virtual void i_one::set(const type_one&, int) | |
66 | virtual void set (const type_one & val, int id) = 0; | |
67 | ^~~ | |
68 | main.cpp:53:8: error: request for member ‘set’ is ambiguous | |
69 | i12->set(type_two ()); | |
70 | ^~~ | |
71 | main.cpp:20:16: note: candidates are: virtual void i_two::set(const type_two&) | |
72 | virtual void set (const type_two & val) = 0; | |
50 | ||
51 | int | |
52 | main () | |
53 | { | |
54 | OneTwo ot; | |
55 | ||
56 | i_one_two *i12 = &ot; | |
57 | ||
58 | i12->set(type_one (), 111); // error: request for member ‘set’ is ambiguous | |
59 | i12->set(type_two ()); // error: request for member ‘set’ is ambiguous | |
60 | return 0; | |
61 | } | |
62 | ||
63 | //============================== | |
64 | main.cpp: In function ‘int main()’: | |
65 | main.cpp:52:8: error: request for member ‘set’ is ambiguous | |
66 | i12->set(type_one (), 111); | |
67 | ^~~ | |
68 | main.cpp:20:16: note: candidates are: virtual void i_two::set(const type_two&) | |
69 | virtual void set (const type_two & val) = 0; | |
70 | ^~~ | |
71 | main.cpp:14:16: note: virtual void i_one::set(const type_one&, int) | |
72 | virtual void set (const type_one & val, int id) = 0; | |
73 | 73 | ^~~ |
74 | main.cpp:14:16: note: virtual void i_one::set(const type_one&, int) | |
75 | virtual void set (const type_one & val, int id) = 0; | |
76 | ^~~ | |
77 | ||
78 | ||
74 | main.cpp:53:8: error: request for member ‘set’ is ambiguous | |
75 | i12->set(type_two ()); | |
76 | ^~~ | |
77 | main.cpp:20:16: note: candidates are: virtual void i_two::set(const type_two&) | |
78 | virtual void set (const type_two & val) = 0; | |
79 | ^~~ | |
80 | main.cpp:14:16: note: virtual void i_one::set(const type_one&, int) | |
81 | virtual void set (const type_one & val, int id) = 0; | |
82 | ^~~ | |
83 | ||
84 |