Xcode中的Objective-C ++和.cpp文件 [英] Objective-C++ and .cpp files in Xcode

查看:133
本文介绍了Xcode中的Objective-C ++和.cpp文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个简单的Objective-C ++应用程序。我的所有代码编译良好,包括在Objective-C类中使用C ++,直到我尝试并添加一个C ++类到混合。我创建了一个简单的C ++类:

I'm trying to make a simple Objective-C++ applicaiton. All of my code is compiling fine, including the use of C++ in Objective-C classes, until I try and add a C++ class to the mix. I've created a simple C++ class:

Test.h

class Test {

};

并将此文件包含在Objective-C类中(扩展名为.mm)以下构建错误:

and included this file in a Objective-C class (with a .mm extension) and I get the following build error:

error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Test'

显然,我在这里缺少一些简单的概念。我会感谢一些启发。

Clearly I'm missing some simple concept here. I'd appreciate some enlightment.

推荐答案

helixed的答案将无济于事,如果__cplusplus未定义,你的类将被预处理器忽略。

helixed's answer will not help, your class will be just skiped by preprocessor if __cplusplus undefined.

最重要的是你试图从* .m文件中包含C ++类,请尝试将其重命名为* .mm。
这解决了同样的问题在我身边。

Most of all you trying to include C++ class from *.m file, try to rename it to *.mm. This solve the same problem on my side.

这篇关于Xcode中的Objective-C ++和.cpp文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆