I guess I don’t understand templates well enough to solve this relatively simple issue.
I want to limit some values based on an enum. I tried setting the enum’s underlying type to int but the compiler still complains with “No matching function call”.
enum GammaMode : int {
kGammaBrighter = 0,
kGammaBright,
kGammaNormal,
kGammaDark,
kGammaDarker
};
GammaMode currentGamma;
currentGamma = jlimit(kGammaBrighter, kGammaDarker, currentGamma);
This doesn’t compile either:
enum GammaMode {
kGammaBrighter = 0,
kGammaBright,
kGammaNormal,
kGammaDark,
kGammaDarker
};
int currentGamma;
currentGamma = jlimit(kGammaBrighter, kGammaDarker, currentGamma);
So, what’s the proper way to do this?
Cast them to int and the return to GammaMode
Rail
Thanks…so this works:
enum GammaMode {
kGammaBrighter = 0,
kGammaBright,
kGammaNormal,
kGammaDark,
kGammaDarker
};
int currentGamma;
currentGamma = jlimit((int)kGammaBrighter, (int)kGammaDarker, currentGamma);
I was actually trying to avoid the cast and “do the right thing”. I was hoping that
enum GammaMode: int {...
would essentially do that, but it doesn’t.
I was thinking…
enum GammaMode {
kGammaBrighter = 0,
kGammaBright,
kGammaNormal,
kGammaDark,
kGammaDarker
} currentGamma;
currentGamma = (GammaMode) jlimit ((int) kGammaBrighter, (int) kGammaDarker, (int) currentGamma);
Rail
oxxyyd
January 16, 2018, 10:31am
5
Hmm, don’t think you need any casting at all…
enum GammaMode
{
kGammaBrighter = 0,
kGammaBright,
kGammaNormal,
kGammaDark,
kGammaDarker
} currentGamma;
currentGamma = jlimit(kGammaBrighter, kGammaDarker, currentGamma);