Here is a program demonstrating how to work with the pointer to a function in Objective-C:
#import <Foundation/Foundation.h>
void hello(char str[])
{
NSLog(@"%s", str);
}
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
char word[] = { 'H', 'e', 'l', 'l', 'o', '\0' };
hello(word);
const char* say = "hello, world!";
hello(say);
void (*fnHello)(char[]);
fnHello = hello;
fnHello("bye");
[pool drain];
return 0;
}
The screenshot:
No comments:
Post a Comment