>>In other words, everytime you change a member with the dot operator, don't you have to make an assignment for it to be reflected in the system structure?
I was assuming that it's a structure provided for your own convenience, and also occasionally passed to a system function. In the convenience part, you simply don't use a RectangleType at all - you just work with the MyRectangleType until you need to pass it to a system function, at which point the conversion operator gives you some extent of compatibility. If the system function takes a RectangleType reference as an 'out' parameter though, this obviously won't work. You'd need to then pass an actual RectangleType and then convert to MyRectangleType via some conversion constructor and/or assignment operator.
Depending on the ratio of such system calls vs. just working with the structure itself, the MyRectangleType solution has the potential to be either really useful or really annoying
Another idea I just thought up (though I haven't tested it at all, so I don't know if it'll work):
Code:
struct MyRectangleType
{
RectangleType rt;
int X;
int Y;
int W;
int H;
MyRectangleType(const RectangleType& orig)
:rt(orig)
{
fromRT();
}
operator = (const RectangleType& rhs)
{
rt = rhs;
fromRT();
}
operator RectangleType&()
{
rt.topLeft.x = X;
rt.topLeft.y = Y;
rt.extent.x = W;
rt.extent.y = H;
return rt;
}
void fromRT()
{
X = rt.topLeft.x;
Y = rt.topLeft.y;
W = rt.extent.x;
H = rt.extent.y;
}
};
...
MyRectangleType mrt;
mrt.X = 5;
mrt.Y = 7;
mrt.W = 20;
mrt.H = 30;
someSystemCall(mrt); //where parameter is IN and by reference/value
someOtherCall(mrt); //where parameter is OUT and by reference
mrt.fromRT();
cout << mrt.W << mrt.H << mrt.X << mrt.Y << endl;
mrt = someOtherOtherCall();
cout << mrt.W << mrt.H << mrt.X << mrt.Y << endl;
**EDIT**
No matter what, any solution such as this that heavily involves type conversions will be extremely inefficient compared to just using the original structure or a wrapper around it, as other have suggested. While this may not matter in some cases, in cases where many such conversions are required in a short period of time, there will probably be a noticeable slowdown especially on a Palm. Also, the memory required for the structure will be at least doubled if you use this particular class, which *could* become a problem depending on how much is available at any given time.