what is the benefit for a class to inherit some class as well as have a data member that also has a data member of that same class?

Viewed 25

I was reading the riscv-fesvr code but while reading I came across a C++ concept that I am unable to justify. So the class htif is inherited from a class called chunked_memif_t, and there is class memif_t that has a data member of type chunked_memif_t. Now the htif has a data member of type memif and memif is a friend of class htif. below are some snippet of code

//inside <htif.h>
class htif_t :public chunked_memif_t
{
  ...
  private:
    memif_t mem;
  ...
  friend memif_t;
  ...
};
//inside memif.h
class chunked_memif_t
{
  ...
};

class memif_t
{ 
  ...
  protected:
  chunked_memif_t* cmemif;
};

my question is why do the inheritance in the first place in htif, if its(htif's) object can access the chunked_memif_t through its mem object which in turn has chunked as a data member.

so how was this decided to inherit as well as make an obj of a class that has a data member that the main class is inherited from, I hope my explanation of the question is not confusing.

also what difference does it make to inherit a class publicly or have its object as a public member?

0 Answers
Related