在Xcode中使用C++与Objective-C混编
有时候,出于性能或可移植性的考虑,需要在iOS项目中使用到C++。
假设我们用C++写了下面的People类:
PeopleWrapper *people = [[PeopleWrapper alloc] init]; [people say:@"Hello, Cpp.\n"]; [people release], people = nil;
结果发现编译通不过,提示“iostream file not found”之类的错误。
这是由于ViewController.m实际上也用到了C++代码,同样需要改后缀名为.mm。
修改后缀名后编译通过,可以看到输出“
Hello, Cpp.
”。