Yes, it can be done using composition even better:
Your example doesn't do the same thing. In particular, it does not
move the mouse cursor to the designated point.
Let me elaborate:
struct Point
{
virtual void Get( int &,int & ) = 0;
virtual Point &operator=( const Point & ) = 0;
virtual ~Point() { }
};
struct PointXY : Point
{
int x;
int y;
PointXY( int x,int y ) x(x) , y(y) { }
PointXY( const Point &pt ) { pt.Get(x,y); }
void Get( int &a,int &b ) { a = x; b = y }
Point &operator=( const Point &pt ) { return *this = PointXY(pt); }
virtual PointXY &operator=( const PointXY &pt ) { pt.Get( x,y ); }
};
struct CursorPos : Point
{
CursorPos() { }
CursorPos( const Point &pt ) { int x,y; pt.Get(x,y);
::SetCursorPos(x,y); }
void Get( int &a,int &b ) { ::GetCursorPos( a,b ); }
Point &operator=( const Point &pt ) { return *this = CursorPos(pt); }
};
Cheers!
- Risto -