Last Updated: February 25, 2016
·
1.496K
· dagams

Compiler differences between Obj-C and Obj-C++

I recently had to change an existing class from Obj-C to Obj-C++. After changing the file type, I suddenly got an error from this line:

CFDataGetBytes(MACAddressAsCFData, CFRangeMake(0, kIOEthernetAddressSize), MACAddress);

No matching function for call to CFDataGetBytes

Long story short, it turns out the problem is with the type of the first argument:

CFTypeRef   MACAddressAsCFData;

The Obj-C++ is more rigorous in checking the type. In CFData.h CFDataGetBytes is defined like this:

void CFDataGetBytes(CFDataRef theData, CFRange range, UInt8 *buffer);

Notice it states CFDataRef rather than CFTypeRef - even though CFTypeRef is a void *, the Obj-C++ compiler doesn't accept it. So, the solution is simply

CFDataGetBytes((CFDataRef)MACAddressAsCFData, CFRangeMake(0, kIOEthernetAddressSize), MACAddress);