Cocoa utilises typedef-ed anonymous enum bitfields.
I'm using objective-C++, for better & worse. Inside a .mm file I need to assign 2 bits (bitwise inclusive OR) to a property of the type of one of these enum bitfield types. The libc++ compiler won't have it because it won't give an rvalue of type int to a property of that typedef-ed anonymous enum bitfield.
I understand there is a size difference of enums between C & C++. So what is the work-around for this situation?
My line performing the assignment is akin to:
uiSwipeRightDownRecogniser.direction = Right | Down;
The definition of the bitfield is akin to:
typedef enum
{
Right = 1 << 0,
Left = 1 << 1,
Up = 1 << 2,
Down = 1 << 3
} UISwipeDirection;
The error is:
Cannot initialize a parameter of type 'UISwipeDirection' with an rvalue of type 'int'
That kind of assignment works in a .m file, but not a .mm.
The compiler is Apple's LLVM 3.0 (using libc++).
Just convert it using static_cast
:
uiSwipeRightDownRecogniser.direction = static_cast<UISwipeDirection>(Right | Down);
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