fork download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. virtual void printA() {std::cout << "A " << this << std::endl;}
  6. };
  7.  
  8. struct B
  9. {
  10. virtual void printB() {std::cout << "B " << this << std::endl;}
  11. };
  12.  
  13. struct C : public A, public B
  14. {
  15.  
  16. };
  17.  
  18. using namespace std;
  19.  
  20. int main() {
  21. // your code goes here
  22.  
  23. C* c = new C();
  24. A* a = c;
  25. B* b = c;
  26. C* c2 = dynamic_cast<C*>(b);
  27. a->printA();
  28. b->printB();
  29. c2->printA();
  30. c2->printB();
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
A 0x95d0a10
B 0x95d0a14
A 0x95d0a10
B 0x95d0a14