|
|
|
|
|
by 1718627440
294 days ago
|
|
When do objects need to have function pointers? If the function never changes per object, then you would just directly call the function. When do you use function pointers? When the caller only knows the type of struct foo_ops, but not the actual called function. That's polymorphism. |
|
You can redefine the methods at runtime. If for example I have a logger that logs on the local drive and another one that logs on a networked drive I can swap the method pointer. This is not polymorphism since the object does have to change. I can also load the function from a shared library that is unknown during compilation and use that as part of the objects methods.