fork download
  1. #include <iostream>
  2. #include <cassert>
  3. using namespace std;
  4.  
  5. struct A
  6. { virtual ~A() {} };
  7. struct B : A
  8. { virtual ~B() {} };
  9. struct C
  10. { virtual ~C() {} };
  11. struct D : B, C
  12. { virtual ~D() {} };
  13.  
  14. C *make_c0()
  15. {
  16. return new D;
  17. }
  18.  
  19. C *make_c1()
  20. {
  21. return new C;
  22. }
  23.  
  24. int main()
  25. {
  26. {
  27. auto c = make_c0();
  28. auto a = dynamic_cast<A*>(c);
  29. if (a == nullptr) {
  30. cout << "A from C via D is null\n";
  31. }
  32. }
  33.  
  34. {
  35. auto c = make_c1();
  36. auto a = dynamic_cast<A*>(c);
  37. if (a == nullptr) {
  38. cout << "A from C without D is null\n";
  39. }
  40. }
  41.  
  42. // your code goes here
  43. return 0;
  44. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
A from C without D is null