I have the following class:
class Point2D
{
protected:
double x;
double y;
public:
double getX() const {return this->x;}
double getY() const {return this->y;}
...
};
Sometimes I need to return the x coordinate, sometimes the y coordinate, so I use a pointer to the member function getX (), getY (). But I canβt return the coordinate, see below, please.
double ( Point2D :: *getCoord) () const;
class Process
{
......
public processPoint(const Point2D *point)
{
if (condition)
{
getCoord = &Point2D::getX;
}
else
{
getCoord = &Point2D::getY;
}
double coord = point->( *getCoordinate ) ();
}
}
Thank you for your help.
source
share