2

For testing I copied following sample code [https://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFCollections/Articles/creating.html] and compiled it:

#import <CoreFoundation/CoreFoundation.h>

CFStringRef strs[3];
CFArrayRef anArray;

strs[0] = CFSTR("String One");
strs[1] = CFSTR("String Two");
strs[2] = CFSTR("String Three");

anArray = CFArrayCreate(NULL, (void *)strs, 3, &kCFTypeArrayCallBacks);

Now I got following error: "No matching function for call to CFArrayCreate"

Why it is not compilable and how to implement it that it is compilable?

3ef9g
  • 781
  • 2
  • 9
  • 19

1 Answers1

6

The type of the second parameter of CFArrayCreate() is const void **. So, change the call to:

anArray = CFArrayCreate(NULL, (const void **)strs, 3, &kCFTypeArrayCallBacks);

This is really only a problem in C++, because it is a lot stricter about converting to and from void*. In C, void* converts to other pointer types freely.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • Correct. The name mangler cannot find a match in C++, but it will in C and also in Objective-C. – guilleamodeo Apr 01 '15 at 08:15
  • 1
    @guilleamodeo, this has nothing to do with the name mangler. It's at compile time, not link time. – Ken Thomases Apr 01 '15 at 15:51
  • Oh. I said that because it looked to me as a link error. 'Not matching found' so on my mind it made sense that the mangler produced a name that didn't match. – guilleamodeo Apr 01 '15 at 21:07