函数期望返回CFDictionaryRef:
CFDictionaryRef xyz()
{
CFMutableDictionaryRef test = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(test, CFSTR("Test"), CFSTR("Test"));
return reinterpret_cast<CFDictionaryRef>(test);
}
可以使用reinterpret_cast进行转换吗?向我抛出一个空的ptr。
您可以安全地进行以下操作:
CFDictionaryRef xyz()
{
CFMutableDictionaryRef test = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(test, CFSTR("Test"), CFSTR("Test"));
return (CFDictionaryRef)test;
}