objc 整数和 C++ 之间的转换Objective C 中的枚举代码
我有一个返回整数的 Objective C 选择器。我有一个需要枚举的 C++ 实例方法。我怎样才能链接它们?当我这样做时,我正在上 Objective C++ (.mm) 课程。
我想这样调用:
TKClass::foo(MyEnum enumVal) { ... }
使用以下返回值:
- (int) intValue { ... }
像这样:
myCPPInstance->foo([myObjCInstance intValue]);
我尝试过强制转换 (foo((MyEnum) [myObjCInstance integerValue])
) 但它不起作用。我绝对不希望我的 Objective C 对象知道有关枚举的任何信息; intValue
需要保持为整数。同样,我真的不想让 C++ 方法在应该接受枚举时担心整数输入。
我不是一个 C++ 程序员,如果这很简单,我很抱歉。
谢谢
编辑:枚举定义如下:
enum MyEnum {
Apples = 0,
Bananas = 1,
Chocolate = 2
};
I have an Objective C selector which returns integers. I have a C++ instance method which expects an enum. How can I link them? I'm in an Objective C++ (.mm) class while I'm doing this.
I want to call this:
TKClass::foo(MyEnum enumVal) { ... }
With the return value of this:
- (int) intValue { ... }
Like this:
myCPPInstance->foo([myObjCInstance intValue]);
I've tried casting (foo((MyEnum) [myObjCInstance integerValue])
) but it doesn't work. I definitely don't want my Objective C object to know anything about the enum; intValue
needs to stay as an integer. Similarly, I don't really want to have the C++ method worry about integer inputs when it should be accepting enums.
I'm not much of a C++ programmer, so sorry if this is easy.
Thanks
EDIT: The enum is defined like this:
enum MyEnum {
Apples = 0,
Bananas = 1,
Chocolate = 2
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个命名空间问题。演员阵容应该是:
It was a namespace issue. The cast should have been: