We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.
Trying to combine Control::EventType::Touch_XXX flags with | operation fails, need to define the OR operator for enum type.
Trying to combine Control::EventType::Touch_XXX flags with | operation fails, need to define the OR operator for enum type.
Bug #2882 [Closed]
This problem is caused by the EventType being a strongly typed enumaration, which, as Sachin said, would require bitwise operators to be declared inside the enum class for bitwise operations to work.
An alternative solution would be to remove the class keyword at the EventType enum declaration, though this probably is undesirable, as this could break existing code.
I’ve created a pull request with Sachin’s suggested solution at https://github.com/cocos2d/cocos2d-x/pull/4103
Status: | Closed | |
---|---|---|
Start date: | 2013-10-06 | |
Priority: | Normal | |
Due date: | ||
Assignee: | - | |
% Done: | 0% |
|
Category: | all | |
Target version: | 3.0-alpha1 |
On cocos2dx 3.0 alpha0, trying to combine touch flags with OR operator fails as touch flags are now enum.
EG, this fails to compile:
(Control::EventType::TOUCH_UP_INSIDE | Control::EventType::TOUCH_UP_OUTSIDE | Control::EventType::TOUCH_CANCEL)
Solution, cocos2dx should define the OR operator for the enum type like this:
Control::EventType operator|(Control::EventType a, Control::EventType b) {
return static_castControl::EventType(static_cast<int>(a) | static_cast<int>(b));
}