简体   繁体   English

如何在iPhone中将C ++代码转换为Objective C代码?

[英]How to Convert C++ code to Objective C Code in iphone?

I have some pure C++ codes are have I want to change the code as objective C code format. 我有一些纯C ++代码,有要更改为目标C代码格式的代码。 How can do this there is an any tools are there or else how can i do this. 如何做到这一点,那里有任何工具,否则我该怎么做。

You can compile C++ code to work on the iphone directly. 您可以编译C ++代码以直接在iPhone上运行。 Keep your core as pure C++, and write the bits that need to talk to objective-C libraries as objective-C++ ( .mm rather than .m IIRC ). 将您的核心保持为纯C ++,并将需要与Objective-C库进行通信的位编写为Objective-C ++(. .mm而不是.m IIRC)。

It's not possible automatically to translate C++ to Objective-C in the sense that you are asking. 按照您的要求,不可能自动将C ++转换为Objective-C。 Picking just one of the large semantic differences at random, C++ allows multiple inheritance and Objective-C doesn't. C ++只是随机选择一个较大的语义差异,它允许多重继承,而Objective-C则不允许。 You therefore can't map the inheritance graph of C++ onto the inheritance graph of Objective-C. 因此,您不能将C ++的继承图映射到Objective-C的继承图。

What you'd do if you were converting manually would be to switch to protocols where what you're meaning to establish is a published set of permissible communications and object composition where you wanted an object to combine some other logic. 如果要手动进行转换,您将要做的就是切换到要建立要发布的一组允许的通信和对象组合的协议,在该协议中您希望一个对象结合其他逻辑。 You'd probably keep the main line of inheritance in a lot of cases. 在很多情况下,您可能都会保留继承的主线。 However you're not going to find a tool capable of automating that process. 但是,您将找不到能够自动执行该过程的工具。

You can refer following question : here 您可以参考以下问题: 这里

and you can compile c++ code directly by changing vc.m to vc.mm 您可以通过将vc.m更改为vc.mm来直接编译c ++代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM