fork download
  1. #include <iostream>
  2.  
  3. struct A {
  4. virtual void run() const = 0;
  5. };
  6.  
  7. struct B : public A {
  8. // uncomment the following line to make the code work
  9. // using A::run;
  10. virtual void run(int) const = 0;
  11. };
  12.  
  13. struct C : public B {
  14. void run() const override {
  15. std::cout << "implementation of A::run\n";
  16. }
  17. };
  18.  
  19. struct D : public C {
  20. void run(int) const override {
  21. std::cout << "implementation of B::run\n";
  22. }
  23. };
  24.  
  25. struct E : public D {};
  26.  
  27. int main() {
  28. const B& obj = E{};
  29. obj.run(); // not visible to the compiler in the overload set
  30. obj.run(5);
  31. return 0;
  32. }
Compilation error #stdin compilation error #stdout 0s 5288KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:29:10: error: no matching function for call to ‘B::run() const’
  obj.run(); // not visible to the compiler in the overload set
          ^
prog.cpp:10:15: note: candidate: ‘virtual void B::run(int) const’
  virtual void run(int) const = 0;
               ^~~
prog.cpp:10:15: note:   candidate expects 1 argument, 0 provided
stdout
Standard output is empty