2010-12-13 52 views
0

我的视图控制器类使用Objective-C++类。我发现我必须用一个.mm扩展名命名C++ imports/includes才能正常工作。但是,我正在使用Interface Builder,它不想与我的视图控制器很好地打在一起.mm文件。我得到编译器分段错误。对这种用例有何建议?Objective-C++和界面生成器的问题

+0

具体是什么样的错误? – nacho4d 2010-12-13 05:29:36

+0

我认为你也需要展示一些代码。 – JeremyP 2010-12-13 09:21:31

+0

在LLVM中,我得到 - > MyViewController.mm:内部编译器错误:在pop_binding中,在cp/name-lookup.c:410。 在gcc 4.2中我得到 - > MyViewController.mm:内部编译器错误:总线错误 – akaru 2010-12-14 00:07:06

回答

0

首先,正如Akaru在他的一个评论中所建议的那样:重命名导入到.mm(整个链)的所有实现文件。

编译错误的另一种可能性:

  1. 确保您不使用C++保留的关键字作为变量名。例如:我在中删除了变量,在重命名的.m实现文件中。我必须将其更改为.mm文件中的any_other_delete_varible_name。最有可能的变量名如:friend, delete, typeid是从最大的犯罪嫌疑人;-)

报价: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++编译器对于类型转换更为严格(例如:在尝试将NSString分配给id类型等时出现错误)使用技巧来避免它,如果必须的话:声明NSString变量为id本身解决了这个问题。