fork download
  1. #include <iostream>
  2.  
  3. class A {
  4. public:
  5. virtual void foo() { std::cout << "A" << std::endl; }
  6. void bar() { std::cout << "A" << std::endl; }
  7. };
  8.  
  9. class B : public A {
  10. public:
  11. virtual void foo() { std::cout << "B" << std::endl; }
  12. void bar() { std::cout << "B" << std::endl; }
  13. };
  14.  
  15.  
  16. int main(int, char**) {
  17. B b;
  18. A * pA = new A;
  19. A * pA2 = &b;
  20. b.foo(); b.bar();
  21. pA ->foo();
  22. pA->bar();
  23. pA2->foo();
  24. pA2->bar();
  25. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
B
B
A
A
B
A