什么是目标 C++?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3684112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 13:28:21  来源:igfitidea点击:

What is Objective C++?

c++objective-cxcodeobjective-c++

提问by Saurabh

What is Objective C++ and can I use this language in Xcode?

什么是 Objective C++,我可以在 Xcode 中使用这种语言吗?

采纳答案by Doches

Objective-C++ is simply source code that mixes Objective-C classes and C++ classes (two entirely unrelated entities). Your C++ code will work, just as before, and the resulting executable will be linked with the Objective-C runtime, so your Objective-C classes will work as well. You can definitely use it in Xcode -- name your files with the .mmextension.

Objective-C++ 只是混合了 Objective-C 类和 C++ 类(两个完全不相关的实体)的源代码。您的 C++ 代码将像以前一样工作,并且生成的可执行文件将与 Objective-C 运行时链接,因此您的 Objective-C 类也将工作。你绝对可以在 Xcode 中使用它——用.mm扩展名命名你的文件。

Also, you might want to read Apple's (sadly deleted, but archived) documentation on Objective-C++.

此外,您可能想阅读Apple 关于 Objective-C++ 的(遗憾的是已删除,但已存档)文档

回答by Pablo Santa Cruz

Objective-C++ is Objective-C (probably with Cocoa Framework) with the ability to link with C++ code (probable classes).

Objective-C++ 是具有与 C++ 代码(可能的类)链接的能力的 Objective-C(可能带有 Cocoa 框架)。

Yes, you can use this language in Xcode to develop for Mac OS X, iPhone/iPodTouch, iPad. It works very well.

是的,您可以在 Xcode 中使用这种语言为 Mac OS X、iPhone/iPodTouch、iPad 进行开发。它运作良好。

You don't have to do anything weird in your project to use Objective-C++. Just name your Objective-C files with the extension .mm(instead of .m) and you are good to go.

你不必在你的项目中做任何奇怪的事情来使用 Objective-C++。只需使用扩展名.mm(而不是.m)命名您的 Objective-C 文件,就可以了。

It is my favorite architecture: develop base class library of my game/application in C++ so I can reuse it in other platforms (Windows, Linux) and use Cocoa just for the iPhone/iPad UIspecific stuff.

这是我最喜欢的架构:用 C++ 开发我的游戏/应用程序的基类库,以便我可以在其他平台(Windows、Linux)中重用它,并将 Cocoa 仅用于 iPhone/iPad UI特定的东西。

回答by John Riselvato

If you want to use Objective-c++ but don't want to name your files .mmcheckout my answer to a similar question.

如果您想使用 Objective-c++ 但不想命名您的文件,请查看.mm我对类似问题的回答

Without changing any .m to .mm or anything like that, if you click your project, click tagets->build settings go all the way down to "LLVM GCC 4.2 - Languages"(new xcode says "Apple LLVM compiler 4.2") you will see Compile Sources Aschange that value to Objective-C++;

在不将任何 .m 更改为 .mm 或类似内容的情况下,如果单击您的项目,单击 tagets->build settings 一直到 “LLVM GCC 4.2 - Languages”(新的 xcode 说“Apple LLVM compiler 4.2”)你将看到Compile Sources As将该值更改为Objective-C++