fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Parent {
  5. public:
  6. virtual void f() { cout << "Parent" << endl; }
  7. };
  8.  
  9. class Child : public Parent {
  10. public:
  11. void f() { cout << "Child" << endl; }
  12. };
  13.  
  14. void t1(Parent * p) { p->f(); }
  15. void t2(Parent & p) { p.f(); }
  16.  
  17. int main() {
  18. Child a;
  19.  
  20. t1(&a);
  21. t2(a);
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
Child
Child