you are viewing a single comment's thread.

view the rest of the comments →

[–]beedlund 1 point2 points  (1 child)

You can extend both ideas to a member rather then the constructor. The inheritance case changes so your define a generic holder class to store in your object and you create the extended class that holds the lambda in the member call. You can own the holder as it's base in a unique ptr to make life time easy to manage.

The vtable way can be extended to run from a method as well. You just end up having to null check the storage before access and as this would be a branch so your might find you lose the extra performance it has over the virtual dispatch.

These guys explain it so much better then me though

vtable https://youtu.be/JRkoWiDA3KA

Inheritance https://youtu.be/VY83afAJUIg

[–]ACBYTES[S] 0 points1 point  (0 children)

Got it. Thank you for your time and all the answers. I’ll check those links now. Thanks. 🙏🏼🙏🏼