PanZefir

Function Hiding

Jun 3rd, 2021 (edited)
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base {
  5. public:
  6.     void fun()
  7.     {
  8.         cout << "void" << endl;
  9.     }
  10.  
  11.     void fun(int i)
  12.     {
  13.         cout << "Base" << endl;
  14.     }
  15. };
  16.  
  17. class Derived : public Base {
  18. public:
  19.     //using Base::fun; // comment/uncomment this line
  20.  
  21.     int fun(char c)
  22.     {
  23.         cout << "Derived" << endl;
  24.         return 0;
  25.     }
  26. };
  27.  
  28. int main()
  29. {
  30.     Derived d;
  31.  
  32.     //d.fun(); // error unless uncomented 'using' line in Derived class
  33.     d.Base::fun();
  34.  
  35.     d.fun(1);
  36.     d.Base::fun(1);
  37.  
  38.     d.fun('a');
  39.  
  40.     return 0;
  41. }
Add Comment
Please, Sign In to add comment