Advertisement
dllbridge

Untitled

Aug 9th, 2023
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include   <stdio.h>
  5.  
  6. ///////////////////////////////////////////////////
  7. class A
  8. {
  9.  
  10.     int x;
  11.  
  12.   public:
  13.     void Func1(){ printf("Func1( )\n"); };
  14.     void Func2(int i)
  15.     {
  16.        
  17.         x = i;
  18.        
  19.         printf("Func2(A)\n");
  20.    
  21.     };
  22.    
  23.     int Func4()
  24.     {
  25.        
  26.       return x;
  27.     }
  28. };
  29.  
  30.  
  31.  
  32. ///////////////////////////////////////////////////
  33. class B: public A
  34. {
  35.  
  36.      int y;
  37.  
  38.    public:
  39.      void Func2(){ printf("Func2(B)\n"); };
  40.      void Func3()
  41.      {
  42.            
  43.           printf("x = %d, Func3( )\n", Func4());
  44.      };
  45. };
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. ////////////////////////////////////////////////////
  54. int main()                                        //
  55. {
  56.  
  57.     B b;
  58.    
  59.  
  60.    
  61.     b.Func1();                                    //           унаследован от A
  62.     b.Func2();                                    //  переопределена в классе B
  63.     b.A::Func2(2);                                 //   версия Func2 из класса A
  64.     b.Func3();                                    //      определена в классе B
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement