fork download
  1. #include <iostream>
  2.  
  3. class Foo
  4. {
  5. public:
  6. static void func() { std::cout << "Foo::func" << std::endl; }
  7. };
  8.  
  9. class Bar : public Foo
  10. {
  11. public:
  12. static void func() { std::cout << "Bar::func" << std::endl; }
  13. };
  14.  
  15. int main(void)
  16. {
  17. Foo::func(); // Works
  18. Bar::func(); // Works
  19.  
  20. Foo foo;
  21. Bar bar;
  22.  
  23. foo.func(); // Works
  24. bar.func(); // Works
  25. bar.Foo::func(); // Works
  26.  
  27. Foo* foobar = new Bar;
  28.  
  29. foobar->func(); // Not the result expected
  30. // Because no override.
  31. return 0;
  32. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Foo::func
Bar::func
Foo::func
Bar::func
Foo::func
Foo::func