#include <iostream> using namespace std; class A{}; class B:public A{}; int main() { A* ptr = new B(); B* b = dynamic_cast<B*>(ptr); // your code goes here return 0; }
Standard input is empty
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);
^
Standard output is empty