fork download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. void do_something() { std::cout << "A::do_something\n"; }
  6. };
  7.  
  8. struct B : public A
  9. {
  10. virtual void do_something() override { std::cout << "B::do_something\n"; }
  11. };
  12.  
  13. int main()
  14. {
  15. A a;
  16. B b;
  17.  
  18. A* ptr = &a ;
  19. ptr->do_something();
  20.  
  21. ptr = &b;
  22. ptr->do_something();
  23. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:10:18: error: ‘virtual void B::do_something()’ marked override, but does not override
     virtual void do_something() override { std::cout << "B::do_something\n"; }
                  ^
stdout
Standard output is empty