fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class one{
  6. int a;
  7. public:
  8. void get(int);
  9. void show();
  10. };
  11.  
  12. class two:public one
  13. {
  14. int b;
  15. public:
  16. void getb(int);
  17. void dis();
  18. void show();
  19. };
  20.  
  21. void one::get(int x) //if i write void two::get(int x) here it gives error
  22. {
  23. a = x;
  24. }
  25.  
  26. void one::show() //same goes for this function why can't i define it as `void two::show()`?
  27. {
  28. cout << a << endl;
  29. }
  30.  
  31. void two::show() //no problem !!
  32. {
  33. cout << "two's version" << endl;
  34. }
  35.  
  36. int main()
  37. {
  38. two ob;
  39. int x;
  40. cin >> x;
  41. ob.get( x );
  42. ob.show();
  43. ob.one::show();
  44. }
Success #stdin #stdout 0s 4404KB
stdin
Standard input is empty
stdout
two's version
21858