Hacker News new | ask | show | jobs
by wosined 293 days ago
> When do objects need to have function pointers?

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.

1 comments

I would call that polymorphism, since the object type the caller sees, still stays the same, i.e. the vtable itself or some containing struct/class. So as far as the caller is concerned, the object he has access to behaves differently.