fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class B {
  5. int x; // just to make sure the result is not due to EBO
  6. public: virtual void foo() { cout << "B::foo\n"; }
  7. };
  8.  
  9. class D : public B {
  10. int y; // just to make sure the result is not due to EBO
  11. public: virtual void foo() { cout << "D::foo\n"; }
  12. };
  13.  
  14. class DD : public D {
  15. int z; // just to make sure the result is not due to EBO
  16. public: virtual void foo() { cout << "DD::foo\n"; }
  17. };
  18.  
  19. int main() {
  20. B* pb = new DD();
  21. pb->foo();
  22. cout << hex << pb << endl;
  23.  
  24. D* pd = static_cast<D*>(pb);
  25. pd->foo();
  26. cout << hex << pd << endl;
  27.  
  28. DD* pdd = static_cast<DD*>(pb);
  29. pdd->foo();
  30. cout << hex << pdd << endl;
  31.  
  32. // your code goes here
  33. return 0;
  34. }
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
DD::foo
0x9f47008
DD::foo
0x9f47008
DD::foo
0x9f47008