fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Shape {
  5. public:
  6. virtual void virtualfunc() { std::cout << "In shape\n"; }
  7. };
  8.  
  9. class Circle: public Shape {
  10. public:
  11. void virtualfunc() { std::cout << "In Circle\n"; };
  12. };
  13.  
  14. int main() {
  15. Shape shape_instance;
  16. Circle circle_instance;
  17.  
  18. Shape& ref_shape = shape_instance;
  19. ref_shape = circle_instance;
  20. ref_shape.virtualfunc();
  21.  
  22. Shape& ref2 = circle_instance;
  23. ref2.virtualfunc();
  24. }
  25.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
In shape
In Circle