#include <iostream>
#include <cassert>
using namespace std;
struct A
{ virtual ~A() {} };
struct B : A
{ virtual ~B() {} };
struct C
{ virtual ~C() {} };
struct D : B, C
{ virtual ~D() {} };
C *make_c0()
{
return new D;
}
C *make_c1()
{
return new C;
}
int main()
{
{
auto c = make_c0();
auto a = dynamic_cast<A*>(c);
if (a == nullptr) {
cout << "A from C via D is null\n";
}
}
{
auto c = make_c1();
auto a = dynamic_cast<A*>(c);
if (a == nullptr) {
cout << "A from C without D is null\n";
}
}
// your code goes here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2Fzc2VydD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBBCnsgdmlydHVhbCB+QSgpIHt9IH07CnN0cnVjdCBCIDogQQp7IHZpcnR1YWwgfkIoKSB7fSB9OwpzdHJ1Y3QgQwp7IHZpcnR1YWwgfkMoKSB7fSB9OwpzdHJ1Y3QgRCA6IEIsIEMKeyB2aXJ0dWFsIH5EKCkge30gfTsKCkMgKm1ha2VfYzAoKQp7CglyZXR1cm4gbmV3IEQ7Cn0KCkMgKm1ha2VfYzEoKQp7CglyZXR1cm4gbmV3IEM7Cn0KCmludCBtYWluKCkgCnsKCXsKCQlhdXRvIGMgPSBtYWtlX2MwKCk7CgkJYXV0byBhID0gZHluYW1pY19jYXN0PEEqPihjKTsKCQlpZiAoYSA9PSBudWxscHRyKSB7CgkJCWNvdXQgPDwgIkEgZnJvbSBDIHZpYSBEIGlzIG51bGxcbiI7CgkJfQoJfQoJCgl7CgkJYXV0byBjID0gbWFrZV9jMSgpOwoJCWF1dG8gYSA9IGR5bmFtaWNfY2FzdDxBKj4oYyk7CgkJaWYgKGEgPT0gbnVsbHB0cikgewoJCQljb3V0IDw8ICJBIGZyb20gQyB3aXRob3V0IEQgaXMgbnVsbFxuIjsKCQl9Cgl9CgkKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCXJldHVybiAwOwp9