问题
My view controller class utilizes an Objective-C++ class. I discovered that I must name it with an .mm extension for C++ imports/includes to work properly. However, I am using Interface Builder, and it does not want to play nicely with my view controller being a .mm file. I get compiler segmented errors. Any suggestions for such a use case?
回答1:
First, as Akaru suggested in one of his comments: rename all implementataion files imported to the .mm (entire chain).
Another possibilities of compilation errors:
- Make sure you do not use c++ reserved keywords as variable names. Example: I had delete variable in renamed .m implementation file. I had to change it to any_other_delete_varible_name in .mm file. Most probably, variable names such as:
friend, delete, typeid
are the biggest suspects ;-)
Quote from: http://cs.smu.ca/~porter/csc/ref/cpp_keywords.html:
There are another 30 reserved words that were not in C, are therefore new to C++, and here they are:
asm dynamic_cast namespace reinterpret_cast try
bool explicit new static_cast typeid
catch false operator template typename
class friend private this using
const_cast inline public throw virtual
delete mutable protected true wchar_t
2 . C++ compiler is more strict about type casting (for example: I was getting error when trying to assign NSString to id type, etc...) Use tricks to avoid it if there is a must: declaring NSString variable as id itself solved the problem.
来源:https://stackoverflow.com/questions/4425938/trouble-with-objective-c-and-interface-builder