In C++, is it legal / correct to use switch statement directly on an object which has an implicit conversion to int ? Instead of using a method returning the object tag.
class Action
{
public:
enum EType { action1, action2, action3};
operator int() const { return mType; }
private:
EType mType;
/* ... */
}
int main()
{
Action a = /* ... */
switch(a)
{
case Action::EType::action1:
/* ... */
break;
case Action::EType::action2:
/* ... */
}
}