Paste #134205

   
pasted on 05.05.2020 14:29
  • Edit to this paste
  • Print
  • Raw
  • The following pastes replied to this paste:  # 134206
  • Show paste tree
  • Compare with paste
    #  
  • Toggle line numbers
  • Syntax highlighting  
Text paste
 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>

class type_one
{
};

class type_two
{
};

class i_one
{
public:
  virtual void set (const type_one & val, int id) = 0;
};

class i_two
{
public:
  virtual void set (const type_two & val) = 0;
};



class i_one_two:public i_one, public i_two
{
};


class OneTwo:public i_one_two
{
public:
  void set (const type_one & val, int id)
  {
    std::cout << "type_one value, id = " << id;
  }

  void set (const type_two & val)
  {
    std::cout << "type_two value\n";
  }
};


int
main ()
{
  OneTwo ot;

  i_one_two *i12 = &ot;

  i12->set(type_one (), 111); // error: request for member ‘set’ is ambiguous
  i12->set(type_two ());      // error: request for member ‘set’ is ambiguous
  return 0;
}

//==============================
main.cpp: In function int main():
main.cpp:52:8: error: request for member set is ambiguous
   i12->set(type_one (), 111);
        ^~~
main.cpp:20:16: note: candidates are: virtual void i_two::set(const type_two&)
   virtual void set (const type_two & val) = 0;
                ^~~
main.cpp:14:16: note:                 virtual void i_one::set(const type_one&, int)
   virtual void set (const type_one & val, int id) = 0;
                ^~~
main.cpp:53:8: error: request for member set is ambiguous
   i12->set(type_two ());
        ^~~
main.cpp:20:16: note: candidates are: virtual void i_two::set(const type_two&)
   virtual void set (const type_two & val) = 0;
                ^~~
main.cpp:14:16: note:                 virtual void i_one::set(const type_one&, int)
   virtual void set (const type_one & val, int id) = 0;
                ^~~
Add Comment
Author