fork download
  1. #include <iostream>
  2.  
  3. class base
  4. {
  5. public:
  6. virtual void print() { std::cout << "base"; }
  7. };
  8.  
  9. class derived : public base
  10. {
  11. private:
  12. virtual void print() { std::cout << "derived"; }
  13. };
  14.  
  15. int main()
  16. {
  17. base * base_ptr = new derived();
  18. base_ptr->print();
  19. delete base_ptr;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
derived