About Monkey 2 › Forums › Monkey 2 Programming Help › external "nameless" enums
This topic contains 4 replies, has 2 voices, and was last updated by
Danilo
2 years, 7 months ago.
-
AuthorPosts
-
September 13, 2016 at 2:00 pm #3919
I’ve encountered that type of “nameless” enum in an external class
[/crayon]Monkey123456789101112131415161718192021222324252627[crayon-5cba16a4ed2fe453078195 inline="true" ]class b2Draw{public:b2Draw();virtual ~b2Draw() {}enum{e_shapeBit = 0x0001, ///< draw shapese_jointBit = 0x0002, ///< draw joint connectionse_aabbBit = 0x0004, ///< draw axis aligned bounding boxese_pairBit = 0x0008, ///< draw broad-phase pairse_centerOfMassBit = 0x0010 ///< draw center of mass frame};/// Set the drawing flags.void SetFlags(uint32 flags);/// Get the drawing flags.uint32 GetFlags() const;/// Append flags to the current flags.void AppendFlags(uint32 flags);/// Clear flags from the current flags.void ClearFlags(uint32 flags);I can change flags by doing the bit additions myself and setting flag to 1,2,4,8,16 if i want only one flag to be “on” or adding any of these to get several ones.
But I’ll have a “expecting identifier” if I try to declare nameless enum:[/crayon]Monkey123456789101112[crayon-5cba16a4ed304672945244 inline="true" ]Class b2Draw Extends Void AbstractEnume_shapeBite_jointBite_aabbBite_pairBite_centerOfMassBitEndMethod SetFlags(flags:uInt)Method GetFlags:uInt()Method AppendFlags(flags:uInt)Method ClearFlags(flags:uInt)But I’d like to implement it using the e_shapebit, e_xxxxxx enums. For it to be looking like the original.
Will I have to implement a new enum with some name or can I use as it is?(and how).thx
September 13, 2016 at 3:51 pm #3922Try something like:
Monkey123456789Class b2Draw Extends Void AbstractConst e_shapeBit:uIntConst e_jointBit:uIntConst e_aabbBit:uIntConst e_pairBit:uIntConst e_centerOfMassBit:uIntMethod SetFlags(flags:uInt)or:
Monkey123456789Class b2Draw Extends Void AbstractConst e_shapeBit:uInt = "b2Draw::e_shapeBit"Const e_jointBit:uInt = "b2Draw::e_jointBit"Const e_aabbBit:uInt = "b2Draw::e_aabbBit"Const e_pairBit:uInt = "b2Draw::e_pairBit"Const e_centerOfMassBit:uInt = "b2Draw::e_centerOfMassBit"Method SetFlags(flags:uInt)If the C++ class ‘b2Draw’ is within a namespace, you probably need
to use the full name-qualifier, like:Monkey123Const e_shapeBit:uInt = "TheNamespace::b2Draw::e_shapeBit"September 15, 2016 at 6:55 am #3952Did it help you, and is it working now?
September 15, 2016 at 9:08 am #3953Just tried it..
first suggestion works if I use:
b2Draw_ext.SetFlags(b2Draw.e_shapeBit | b2Draw.e_jointBit) for example
or
b2Draw_ext.SetFlags(b2Draw_ext.e_shapeBit | b2Draw_ext.e_jointBit)just e_shapeBit alone won’t work but it’s sufficient for me. May be work on that a bit more but if all goes well like that I’ll keep it so.
thanks!
September 15, 2016 at 3:26 pm #3957If you want to just use the e_*** constants without the class name,
you could add them additionally to Extern section – outside of a class.Monkey12345678ExternConst e_shapeBit:uInt = "b2Draw::e_shapeBit"Const e_jointBit:uInt = "b2Draw::e_jointBit"Const e_aabbBit:uInt = "b2Draw::e_aabbBit"Const e_pairBit:uInt = "b2Draw::e_pairBit"Const e_centerOfMassBit:uInt = "b2Draw::e_centerOfMassBit"Now you should be able to use e_shapeBit|e_jointBit etc.
-
AuthorPosts
You must be logged in to reply to this topic.