Is it possible to pass anonymous enum as a function parameter? Something like that:
class Foo
{
enum
{
One,
Two,
Three
};
};
void Function( /* ??? */ e)
{
switch (e)
{
case Foo::One: // do stuff...
case Foo::Two: // ...
}
}
Solution attempt:
I was trying to determine what's the type of Foo::One by using auto and checking deduced type:
auto u = Foo::One;
But it turned out to be Foo<anonymous enum> so I can't really use that in code.
I found a possible solution. Ugly, but works:
void Function(decltype(Foo::One) e) {}
You could turn the function into a function template like this:
template <class Enum> void Function(Enum e)
{
switch (e)
{
case Foo::One: // do stuff...
case Foo::Two: // ...
}
}
It can be instantiated and called via
Function(Foo::One);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With