In the class below there is a pointer model_
of type OpModel
which is a class. This pointer is initialized in the constructor using new
to create an OpModel
object. That's fine, you have a pointer to a valid object. The method model()
deferences this pointer which access the actual OpModel
object. But what I don't understand is that it returns a reference to CompositionalModel
which is a different class.
I believe that it is related to polymorphism because OpModel
is derived from CompositionalModel
, which is an abstract class. But why would you return a reference to the base class?