I have this problem:
// the classes
class cBase {};
class cDerived : public cBase {};
class cBaseArray
{
// the array of pointers to cBase
cBase** array;
// overloaded operator that returns an element of the array
cBase*& operator[](unsigned index)
{
// much more complicated, but simplified for example
return array[index];
}
};
class cDerivedArray : public cBaseArray
{
// overloaded operator that returns a converted element of the array
cDerived*& operator[](unsigned index)
{
// conversion required, but don't know how
return static_cast<???>(cBaseArray::operator[](index));
}
};
So how do I convert the reference to pointer to cBase returned by the operator[] of cBaseArray to refernce to pointer to cDerived that can be returned by the operator[] of cDerivedArray?
You have to dynamic_cast them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With