如何在我的项目中使用几个C ++文件,而不编译每个文件作为C ++? [英] How can I use a few C++ files in my project without compiling every file as C++?

查看:152
本文介绍了如何在我的项目中使用几个C ++文件,而不编译每个文件作为C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目与基本视图控制器类,由约25其他视图控制器继承。现在我需要在该基类中使用一些核心音频,所以我整合了Audio类(改编自苹果的aurioTouch示例项目)使用C ++。基类导入Audio类的头,然后初始化一个Audio对象,以便我可以调用Audio类中的方法。

I have a project with a base view controller class, that is inherited by about 25 other view controllers. Now I need to use a bit of core audio in that base class, so I'm integrating an Audio class (adapted from Apple's aurioTouch example project) that uses C++. The base class imports the Audio class's header, and then initializes an Audio object so that I can call methods within the Audio class.

当我编译时,在Audio类及其助手类中,'of'=',',',',';','asm'或'属性之前的'!='token,因为编译器跳过C ++语法。如果我将基类的扩展名更改为.mm,我会得到相同的错误;我想我也必须改变继承自基类的所有类的扩展。

When I compile, I get errors like "expected '=', ',', ';', 'asm' or 'attribute' before '!=' token" in the Audio class and its helper classes, because the compiler is tripping over the C++ syntax. If I change the extension of the base class to .mm I get the same errors; I think I will have to also change the extension of all the classes that inherit from the base class.

有没有办法避免这种情况?换句话说,我如何只编译最少量的文件作为C ++ - - 只是Audio类,或Audio类和基类,而不改变项目的其余部分?

Is there a way to avoid this? In other words, how can I compile just the minimum amount of files as C++ -- ideally just the Audio class, or the Audio class and the base class -- without changing the rest of the project?

我问的原因是,这一点音频大约是应用程序的功能的.5%,似乎是错误的改变几十个文件来编译不同,只是因为这一个小的补充。

The reason I ask is that this bit of audio is about .5% of the app's functionality, and it seems wrong to change dozens of files to compile differently just because of this one small addition.

推荐答案

它实际上足以重命名使用C ++功能的 .m 文件 .mm 。你必须确保你的类的头文件中不包含任何C ++头文件,否则其他非C ++类会试图包含你的类的头文件。

It should actually suffice to rename the .m file that uses C++ functionality to .mm. You have to make sure that you don't include any C++ headers in the header file of your class, otherwise the other non-C++ classes will go berserk trying to include your class's header file.

这篇关于如何在我的项目中使用几个C ++文件,而不编译每个文件作为C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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