简体   繁体   English

使用C ++在Objective-c中使用类和框架

[英]classes vs frameworks in Objective-c with C++

I would like to create some libraries in C++, these libraries will be able to model physical phenomena. 我想用C ++创建一些库,这些库将能够模拟物理现象。 I would like to build a cross-platform environment where these libraries are updated independent of the GUI, in my case a PC application and a iOS app would be the clients of such libraries. 我想建立一个跨平台的环境,这些库可以独立于GUI进行更新,在我看来,PC应用程序和iOS应用程序将是这些库的客户端。

In terms of performance, easiness to plug C++ code, etc., what would be your recommendation? 在性能,插入C ++代码的容易性等方面,您的建议是什么? to generate a C++ classes and call them from other classes with the .mm extension or to generate a framework in c++. 生成C ++类并使用.mm扩展名从其他类调用它们,或者用c ++生成框架。

Would you recommend something different to C++ for cross-platform compatibility? 您是否会推荐与C ++不同的内容以实现跨平台兼容性?

NB: I am not an experienced programmer but trying to get into a decent level. 注意:我不是一个经验丰富的程序员,但试图进入一个体面的水平。

Thanks, Alejandro 谢谢,亚历杭德罗

In terms of performance, easiness to plug C++ code, etc., what would be your recommendation? 在性能,插入C ++代码的容易性等方面,您的建议是什么? to generate a C++ classes and call them from other classes with the .mm extension or to generate a framework in c++. 生成C ++类并使用.mm扩展名从其他类调用它们,或者用c ++生成框架。

It depends on the platforms you are aiming to support, but C++ is pretty well supported, so I think there should be no issues at all. 这取决于您希望支持的平台,但C ++得到了很好的支持,所以我认为应该没有任何问题。 C++ is also pretty low-level, so it will give you all the performance you need. C ++也非常低级,因此它将为您提供所需的所有性能。

When it comes to the concept of framework, though, you should beware. 但是,当谈到框架的概念时,你应该注意。 Usually, a framework gives you a set of classes which you reuse in several ways. 通常,框架会为您提供一组可以多种方式重用的类。 One, possibly the most important way is by subclassing (ie, you subclass and specify a missing method, or specialize a generic method). 一种可能是最重要的方式是通过子类化(即,您子类化并指定缺少的方法,或专门化泛型方法)。 You could not really do this, like in: an Objective-C class deriving from a C++ class -- this is not possible (unless you define some kind of wrapper or bridge). 你不可能真的这样做,比如:从C ++类派生的Objective-C类 - 这是不可能的(除非你定义某种包装器或桥接器)。

So you would have your C++ framework, that you can extend using C++, and use from other languages, eg, Objective C. 所以你将拥有你的C ++框架,你可以使用C ++进行扩展 ,并使用其他语言,例如Objective C.

Would you recommend something different to C++ for cross-platform compatibility? 您是否会推荐与C ++不同的内容以实现跨平台兼容性?

Again, as above, but C++ is better than other options (Java, eg, which is not supported on iOS, and less and less supported on MacOS, the major platforms using ObjC). 同样,如上所述,但C ++优于其他选项(Java,例如,iOS不支持,并且在MacOS上使用ObjC的主要平台支持越来越少)。 Possibly only C could give you wider portability. 可能只有C可以为您提供更广泛的便携性。

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

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