c++iosiphonexcode

How can I use a few C++ files in my project without compiling every file as C++?


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.

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.

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?

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.


Solution

  • 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.