In the code below I would like to know what does the operator* overloadind do here.
// struct pointer to Shape
struct PtrToShape
{
Shape *ptr;
bool operator < (const PTRToShape & rhs) const
{ return *ptr < *rhs.ptr; }
const Shape & operator*() const
{ return *ptr; }
};
What will it overload? Will it overload the * operator for the struct or for the shape objects? Is this overloading used in:
return *ptr < *rhs.ptr
And in the line I previously mentioned the * (overloaded or not) refers to what? to rhs or to rhs.ptr ?
Thank you.
This returns a reference dereferenced
Shapeobject, the one calledptr, which is a member of your struct.That overload will overload this
*operatorfor yourPtrToShapestruct.Also, no, it’s not used in
return *ptr < *rhs.ptr