fork download
  1. #include <iostream>
  2. using namespace std;
  3. class A{};
  4. class B:public A{};
  5. int main() {
  6. A* ptr = new B();
  7. B* b = dynamic_cast<B*>(ptr);
  8. // your code goes here
  9. return 0;
  10. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:7:29: error: cannot dynamic_cast ‘ptr’ (of type ‘class A*’) to type ‘class B*’ (source type is not polymorphic)
  B* b = dynamic_cast<B*>(ptr);
                             ^
stdout
Standard output is empty