richtige funktion ??



  • class My{
      int x;
      int y;
      My();
      void set();
    };
    My::My()x(0),y(0){}
    void My::set(){x+=10;y+=10;}
    
    class My2 : public My{
     int z;
     My2();
     void set();
    };
    My2::My2()z(0){}
    void My2::set{
      z+=10;
      this->set();
    }
    

    bei der set funktion von My2
    würde die funktion siche selbst wieder aufrufen
    oder die geerbte funktion
    (wie schaffe ich es das er die geerbte funktion aufruft)



  • du benutzt ja die func von my2



  • ungetestet

    class Base
    {
      private:
        int x;
        int y;
      public:
        Base() : x(0), y(0) {}
        void set() { x += 10; y += 10; }
    };
    
    class Derived : public Base
    {
      private:
        int z;
      public:
        Derived() : Base(), y(0) {}
        void set() { y += 10; Base::set(); }
    };
    

Anmelden zum Antworten