Go Down

Topic: Casting a int as a enum (Read 10 times) previous topic - next topic

PaulS

You need to think in terms of the function being called, not in terms of how to call the function. The function being called could be overloaded:

void Class::SetColor(Color newColor)
{
}

void Class::SetColor(int newColorNum)
{
}

Then, you can call instance.SetColor(White); or instance.SetColor(4);.

EVP

Yes it is overloaded as well. But from what you said with very little change it is now working. I was thinking the wrong way round.

It now work's. Nice one Paul Cheers :)

EVP

I'm basically using this now.

void Class::SetColor(int newColorNum)
{
}

Then, you can call instance.SetColor(White); or instance.SetColor(4);.

Without the enum overloaded version you put. This seems to work if it's sent a enum or a int. Is this because a enum is like a definition of an integer? Is this correct?    


PaulS

Yes, an enum is an int. The converse is not, as you have seen, true.

Go Up