mardi 9 mars 2021

Overloading addition operator in child class in C++

Okay guys imagine situation where I have a parent class and a successfuly overloaded + operator:

   class parent
   {
      public:
         int a; 
         int b;

         friend parent& operator+(parent& mother, const parent& father)
         {
            //add stuff
         }
   }
   class child : public parent
   {
      public:
         int q;

      friend child& operator+(child& brother, const child& sister)
         {
            output = brother.parent + sister.parent;
            output.q = brother.q + sister.q
         }
   }

How can I correctly overload that child addition operator to call the parent, add all the members off the parent class, then add the members of the child class? Can't find any info on this anywhere...

Thanks all

Aucun commentaire:

Enregistrer un commentaire