I need to create a wrapper between C++ and C#. I have a function very similar to this:
virtual SOMEINTERFACE* MethodName(ATTRIBUTE_TYPE attribType = ATTRIBUTE_TYPE::ATTRIB_STANDARD) = 0;
The enum
is declared like this:
enum class ATTRIBUTE_TYPE {
ATTRIB_STANDARD,
ATTRIB_LENGTH
};
How do I wrap that ATTRIBUTE_TYPE enum?
You can change default values of enum elements during declaration (if necessary).
It is not possible to have enum of enums, but you could represent your data by having the type and cause separately either as part of a struct or allocating certain bits for each of the fields.
Enumeration or Enum in C is a special kind of data type defined by the user. It consists of constant integrals or integers that are given names by a user. The use of enum in C to name the integer values makes the entire program easy to learn, understand, and maintain by the same or even different programmer.
So yes, if you do not specify a start value, it will default to 0.
Your C++ enum is defined like this:
enum class ATTRIBUTE_TYPE {
ATTRIB_STANDARD,
ATTRIB_LENGTH
};
By default, enum class
types are int
sized. Which means that you can translate this to C# like so:
enum ATTRIBUTE_TYPE {
ATTRIB_STANDARD,
ATTRIB_LENGTH
};
That's all there is to it. A C# enum is blittable and this C# enum maps exactly on to your C++ enum.
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