fork(1) download
  1. #include <iostream>
  2.  
  3. struct Base
  4. {
  5. virtual void test() { std::cout << "Base" << std::endl; }
  6. };
  7. struct Derived : Base
  8. {
  9. virtual void test() { std::cout << "Derived" << std::endl; }
  10. };
  11.  
  12. void f(Base *base) { base->test(); }
  13. void g(Base &base) { base.test(); }
  14. void h(Base base) { base.test(); }
  15.  
  16. int main()
  17. {
  18. Derived d;
  19. Derived *dp = &d;
  20. Base *bp = dp;
  21.  
  22. f(dp); // Derived
  23. f(bp); // Derived
  24. g(d); // Derived
  25. h(d); // Base
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
Derived
Derived
Derived
Base