I have a parent class called List
and a child class called SortedList
. In List
, I overload +=
so that it calls the member function Insert
. That is:
void List::operator+=(std::string newEntry) {
this->Insert(newEntry);
}
Both List
and SortedList
have an Insert
function. Ideally, if the instance of List
that I'm using is also a SortedList
, SortedList
's Insert
function would be called instead of List
's, but that's not what is happening. I could redefine the above function in SortedList
and every subsequent child class of List
that I will create, but that seems redundant. Is there any way to modify the above function to get the desired behavior?