Why use function pointers in a structure in Objective-C?

I just read this question Use C Struct in Objective-C , and I was wondering why someone would want to use function pointers in structs. Will there be an equivalent replacement of functions in the class?

+3
source share
2 answers

I don’t think you will need something like this in objective-c.

How you apply polymorphism in C. This is similar to an interface definition. Some frameworks (including the kernel file system?) Would expect you to pass a structure with your functions that the infrastructure will call when an event occurs.

If you really need to, I think you could use C ++ and struct / classes from objective-c instead of using simple C structures with function pointers, but you should be fine with objective-c.

+3
source

C , . , , , C, - objective-c.

+2

Source: https://habr.com/ru/post/1730804/


All Articles