fork download
  1. #include <iostream>
  2.  
  3. class Base
  4. {
  5. public:
  6. void function1(){std::cout<<"1"<<std::endl;}
  7. virtual void function2()=0;
  8. };
  9.  
  10. class Derived : public Base
  11. {
  12. public:
  13. virtual void function2(){std::cout<<"2"<<std::endl;}
  14. };
  15.  
  16. int main()
  17. {
  18. Derived d;
  19. void* ptr = static_cast<void*>(&d);
  20. Base* baseptr=static_cast<Base*>(ptr);
  21. baseptr->function1();
  22. baseptr->function2();
  23. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1
2