#include <cassert>

class Base {
 public:
  // virtual function included to make hierarchy polymorphic
  virtual void foo() { }
  float x;
};

class Der1 : public Base {
 public:
  char x;
};

int main(int argc, char** argv) {
  Base b; Der1 d;

  // OK (run-time check passes)
  Base* bptr = dynamic_cast<Base*>(&d);
  assert(bptr != nullptr);

  // OK (run-time check passes)
  Der1* dptr = dynamic_cast<Der1*>(bptr);
  assert(dptr != nullptr);

  // Run-time check fails, so the cast returns nullptr
  bptr = &b;
  dptr = dynamic_cast<Der1*>(bptr);
  assert(dptr != nullptr);

  return 0;
}