fork download
  1. #include <iostream>
  2.  
  3. struct A {
  4. virtual void test() {
  5. std::cout << "A" << std::endl;
  6. }
  7. };
  8. struct B: public A {
  9. virtual void test() {
  10. std::cout << "B" << std::endl;
  11. }
  12. };
  13.  
  14. int main()
  15. {
  16. auto a = new A();
  17. auto b = new B();
  18. auto ap = static_cast<A*>(b);
  19. auto bp = static_cast<B*>(a);
  20. ap->test();
  21. bp->test();
  22. }
  23.  
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
B
A