Invalid conversion from const void* error
I am running the following code in an .mm file and I get the error:
Invalid conversion from 'const void*' to 'const __CFData*'
I need to run the code in .mm. If I change to .m it doesn't complain. Why is it behaving like this? I compile to iPhone
CFSocketNativeHandle native;
CFDataRef nativeProp = CFReadStreamCopyProperty(theReadStream, kCFStreamPropertySocketNativeHandle);
if(nativeProp == NULL)
{
if (errPtr) *errPtr = [self getStreamError];
return NO;
}
CFIndex nativePropLen = CFDataGetLength(nativeProp);
CFIndex nativeLen = (CFIndex)sizeof(native);
CFIndex len = MIN(nativePropLen, nativeLen);
CFDataGetBytes(nativeProp开发者_运维知识库, CFRangeMake(0, len), (UInt8 *)&native);
CFRelease(nativeProp);
CFSocketRef theSocket = CFSocketCreateWithNative(kCFAllocatorDefault, native, 0, NULL, NULL);
if(theSocket == NULL)
{
if (errPtr) *errPtr = [self getSocketError];
return NO;
}
CFReadStreamCopyProperty()
returns CFTypeRef
, which is just a typedef
for const void*
, and C++ is stricter about conversions than C (or Objective-C). You need to cast explicitly here:
CFDataRef nativeProp = (CFDataRef)CFReadStreamCopyProperty(...);
精彩评论