Link to home
Start Free TrialLog in
Avatar of GGRUNDY
GGRUNDY

asked on

user defined assignment

I would love to have a user defined copy function
like this one.

void operator=(RGBQUAD& q, PALETTEENTRY& pe)
{
  q.rgbRed = pe.peRed;
  q.rgbGreen = pe.peGreen;
  q.rgbBlue = pe.peBlue;
  q.rgbReserved = 0;
  }

but to compiler tells me to bugger off.
Is "void Copy(RGBQUAD& q, PALETTEENTRY& pe)"
my only option? Thanks.

ASKER CERTIFIED SOLUTION
Avatar of jasonclarke
jasonclarke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

FYI the reason for this, is because you cannot write an assignment to one of the built-in types.  i.e. it is to prevent you from doing things like

int &operator = (int l, int r);
int operator = (int l, double r);

which have already been defined by the language.  


Note how Jason changed the return value of your function.     This is not required, but it is a customary practice.  by doing that you can "chain" assignments like

a = b = c;
Avatar of GGRUNDY

ASKER

Thanks guys.