fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct A {
  5. virtual void foo() {
  6. cout << "Hello from A" << endl;
  7. }
  8. };
  9.  
  10. struct B: A {
  11. void foo() {
  12. cout << "Hello from B" << endl;
  13. }
  14. };
  15.  
  16. int main() {
  17. A* b = new B();
  18. b->foo();
  19. ((B*)b)->foo();
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Hello from B
Hello from B