fork download
  1. #include<iostream>
  2. using namespace std;
  3. class Base{
  4. public:
  5. virtual void display(){
  6. cout<<"Base\n";
  7. }
  8. };
  9. class Derived:public Base{
  10. public:
  11. void display(){
  12. cout<<"Derived\n";
  13. }
  14. };
  15. int main(){
  16. Base*ptr=new Derived;
  17. Derived*dptr=dynamic_cast<Derived*>(ptr);
  18. dptr->display();
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Derived