我有一个Obj-C类 StuffCompareController.mm
,其实现如下:
@implementation StuffCompareController
int compareThings(char* string1, char* string2)
{
//Some C++ implementation
}
- (BOOL) compareStuff:(NSString *)string1 withImage:(NSString *) string2
{
const char *path1 = [string1 UTF8String];
const char *path2 = [string2 UTF8String];
compareThings((char *) path1, (char *) path2); // This throws an error "No matching call to callThings"
compareThings(NULL, NULL); // But this does not throw any error. It builds fine with this
return NO;
}
@end
我在代码注释中提到的奇怪的事情(对我来说)是为什么第一个调用会抛出错误而不是第二个调用。当我修改第一个调用时:
::compareThings((char *) path1, (char *) path2);
此调用正常,没有错误。为什么会这样?启发我。
更新:
此Obj-C方法compareStuff:
尚未在任何地方调用。它仅在.h文件中声明