views:

87

answers:

1

I'm trying to copy over some example code into my own project. The example project is iPhoneExtAudioFileConvertTest from the sdk. The example project contains a file called ExtAudioFileConvert.cpp. This file contains what looks like Objective-C code:

assert([NSThread isMainThread]);

The example project runs fine, but the compiler complains about the code above when I build my own project: error: expected primary-expression before '[' token

What's going on here? Obviously there's some way to use objective c bracket syntax in a .cpp file. What do I need to do to make it work?

+3  A: 

Change the file extension to .mm for Objective-C++ instead of just .cpp for C++.

thyrgle
Thanks thyrgle, but my question is really how to do it with a .cpp extension.
morgancodes
@morgancodes: Not sure it's possible. And if it is.. I don't see why it matters.
thyrgle
I'm trying to import the audio conversion code in the iPhoneExtAudioFileConvertTest in the sdk into my own project. That project has a .cpp file with the sytax I showed above inside, so it's definitely possible. As to why it matters, I'm just trying to change as little as possible because there's QUITE a lot I don't understand in the example code. Just trying to delicately move it over in one piece if possible.
morgancodes
@morgancodes: Where did you get the project?
thyrgle
@morgancodes: Changing it to .mm will not in anyway hurt your understanding of the code. It just allows you to intermix C++ and Objective-C.
thyrgle
@thyrgle The iPhoneExtAudioFileConvertTest project is from the xCode help documentation.
morgancodes
http://sseyod.blogspot.com/2009/02/objective-c.html shows how to do it alternatively but really, I would just advise you use .mm.
thyrgle
Cool. Thanks for the link. Now on to the next obstacle!
morgancodes
@morgancodes: Will you plz accept my answer then?
thyrgle
Of course. Done.
morgancodes
@morgancodes: Thnx.
thyrgle