If this is possible to do, it shouldn't be too hard. I want to be able to overload the = operator of my zaColor class to take constants like ZA_RED or ZA_GREEN ( from my ZA_COLOR enum ). Look at the code below, and the example of usage in the end of the post. Some C++ and SDL knowledge is needed to understand the code.
I have a color class:
Code: Select all
class zaColor
{
public:
zaColor();
virtual Uint32 GetColor();
zaColor operator=(const ZA_COLOR& color){
SimpleColor = color;
return *this;
}
ZA_COLOR SimpleColor;
protected:
bool RGB;
};
Code: Select all
enum ZA_COLOR { ZA_WHITE, ZA_RED, ZA_GREEN, ZA_BLUE, ZA_GREY, ZA_BLACK };
Code: Select all
void zaDrawRect(SDL_Rect* rect, zaColor* color = NULL);
void zaDrawRect(SDL_Rect* rect, zaColor* color){
if(rect){
if(color)
SDL_FillRect(pScreen, rect, color->GetColor());
else{
SDL_FillRect(pScreen, rect, SDL_MapRGB(pScreen->format, 0xFF, 0xFF, 0xFF));
}
}
}
I want to be able to do this in the main function:
Code: Select all
zaColor temp = ZA_RED;
zaDrawRect(200, 50, &temp);
Code: Select all
zaDrawRect(200, 50, ZA_RED);
Thanks for any help that partially or completely solves my problem.
Edit:
If it wasn't clear, the problem is that the operator= function doesn't work.
if I write:
zaColor temp = ZA_RED;
I get the compile error:
"error: conversion from 'ZA_COLOR' to non-scalar type 'zaColor' requested"