【发布时间】:2017-06-30 13:59:33
【问题描述】:
我无法使用 SWIG 将 c++ 枚举成员包装到 C#。 c++ 枚举成员的大小超过 Int32。在 C# 中,枚举成员的默认类型是 Int32,因此我有编译错误。虽然我关注了instructions,但也解决不了问题。
MyClass.h
class MyClass
{
public:
MyClass() {}
~MyClass() {}
enum BigNumbers
{
big = 0x80000000, bigger
};
};
MyClass.i
%module cpp
%{
#include "MyClass.h"
%}
%include "MyClass.h"
%typemap(csbase) BigNumbers "uint"
%inline %{
enum BigNumbers { big=0x80000000, bigger };
%}
结果我在生成的 c# 包装器中得到关注成员,这导致编译错误cannot implicitly convert type 'uint' to 'int'
MyClass.cs
public enum BigNumbers {
big = 0x80000000,
bigger
}
和单独文件中的全局 uint 枚举:
BigNumbers.cs
public enum BigNumbers : uint {
big = 0x80000000,
bigger
}
虽然我想以 MyClass 成员的身份在 MyClass.cs 中获得它。
请大家帮帮我!
【问题讨论】:
-
您可以为
enum指定底层类型 -
我只是在学习 SWIG。你能多写一点吗?
-
我对 SWIG 一无所知,但您可以像这样定义枚举类型
public enum MyEnum : long { whatever = long.MaxValue } -
是的!这正是我想从 C++ 代码中的枚举中自动获得的,但不能