Objective-C ++和Interface Builder出现问题 [英] Trouble with Objective-C++ and Interface Builder
问题描述
我的视图控制器类使用Objective-C ++类。我发现我必须使用.mm扩展名为C ++ import / includes命名才能正常工作。但是,我正在使用Interface Builder,它不希望我的视图控制器是一个.mm文件。我得到编译器分段错误。有关此类用例的任何建议吗?
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?
推荐答案
首先,正如Akaru在他的一条评论中所建议的那样:重命名导入.mm(整个链)的所有文件。
First, as Akaru suggested in one of his comments: rename all implementataion files imported to the .mm (entire chain).
编译错误的另一种可能性:
Another possibilities of compilation errors:
- 确保不使用c ++保留关键字作为变量名称。示例:我在重命名的.m实现文件中有删除变量。我必须在.mm文件中将其更改为 any_other_delete_varible_name 。最可能的是,变量名称如:
friend,delete,typeid
是最大的嫌疑人; - )
- 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 ;-)
引自: http://cs.smu.ca /~porter/csc/ref/cpp_keywords.html :
还有另外 30个保留字不是在C中,是
因此是C ++的新手,在这里它们是:
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 ++编译器对类型转换更严格(例如:我在尝试将NSString分配给id类型时遇到错误等等)。如果有必要,请使用技巧来避免它:声明 NSString 变量 id 本身解决了问题。
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.
这篇关于Objective-C ++和Interface Builder出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!