-
Me again
anyone know what this means?
I'm trying to overload the = operator with this code
union Colour
{
RGBQUAD ColourComponents; //allows access to the colour components Provided for compatibility only
unsigned char ColourBytes[4];
unsigned long ColourLongVal; //a long value for use externaly
};
Colour& operator= (Colour& Target, Colour& NewValue)
{
Target.ColourLongVal = NewValue.ColourLongVal;
return NewValue;
}
Colour& operator= (Colour& Target, long NewValue)
{
Target.ColourLongVal = NewValue;
return Target;
}
Colour& operator= (long& Target, Colour& NewValue)
{
Target = NewValue.ColourLongVal;
return NewValue;
}
Why am I getting an error, it's working for other operators.
-
Ok, I've found out why it is, I have to declare the operators inside the union as members. So now I run into problems.
I want to make of much of this union private as I can, so I don't want to have to assign colours to long integers like this
long MyLong;
Colour MyColour = 0x 0000FF00; //make colour green
MyLong = MyColour.Value;
Is there a way to overload the assignment operator to do this? (I also want to create some other more complicated types that don't store the numbers in the same way as everything else, ie a short where 0x8000 represents 1. I'd like this encapsulated as much as possible so that it acts like a normal number.
Any help would be greatly appreciated.