Advertisement
KShah

Untitled

Feb 25th, 2022
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. struct Base {
  4.     virtual void f() {
  5.         std::cout << 1;
  6.     }
  7. };
  8.  
  9. struct Derived: Base {
  10.     virtual void f() {
  11.         std::cout << 2;
  12.     }
  13. };
  14.  
  15. struct Subderived: Derived {
  16.     void f() {
  17.         std::cout << 3;
  18.     }
  19. };
  20.  
  21. int main() {
  22.     Derived d;
  23.     Base& b = d;
  24.     b.f();
  25.    
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement