Projects > cpp > Issues > Bug #2882

We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.

Create Issue on Github

Trying to combine Control::EventType::Touch_XXX flags with | operation fails, need to define the OR operator for enum type.

Bug #2882 [Closed]
schngrg 2013-10-06 09:14 . Updated over 5 years ago

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));

elwinarens 2013-10-12 22:40

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.

Xrmo 2013-11-06 03:06

I’ve created a pull request with Sachin’s suggested solution at

zhangxm 2013-11-15 03:43
  • Status changed from New to Closed

Atom PDF

Start date:2013-10-06
Due date:
% Done:


Target version:3.0-alpha1