fork download
  1. #include <iostream>
  2.  
  3. struct base
  4. {
  5. virtual ~base() {}
  6. virtual void foo() const { std::cout << "base::foo\n" ; }
  7. void bar() const { std::cout << "base::bar\n" ; }
  8. };
  9.  
  10. struct derived : base
  11. {
  12. virtual void foo() const override
  13. { std::cout << "derived::foo overrides base::foo\n" ; }
  14.  
  15. void bar() const
  16. { std::cout << "derived::bar hides base::bar\n" ; }
  17. };
  18.  
  19. void fun( const base& b )
  20. {
  21. b.foo() ;
  22. b.bar() ;
  23. }
  24.  
  25. int main()
  26. {
  27. derived d ;
  28. fun(d) ;
  29. }
  30.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
derived::foo overrides base::foo
base::bar