4 ms·
You mentioned being "an embedded C++ shop" in another comment, so I'll frame this in C/C++. One way is to assign function pointers within a struct which is sha
by AdieuToLogic 9y ago
You mentioned being "an embedded C++ shop" in another comment, so I'll frame this in C/C++.
One way is to assign function pointers within a struct which is shared across top level functions. This is very common in C, such as in the standard i/o library. It is also very handy in dynamic module initialization in both C and C++, such what Apache httpd supports.
In-process C++ polymorphism of course can be done the same way, but using classes is the idiomatic approach. An interesting and highly useful form of polymorphism in C++ is tag dispatching[0] in templates. This can be complemented with usage of traits to achieve very flexible implementations.
A book I highly recommend which discusses these techniques as well as C++ templates in detail is "C++ Templates The Complete Guide"[1].
0 - http://www.boost.org/community/generic_programming.html#tag_dispatching http://www.boost.org/community/generic_programming.html#tag_...
1 - https://www.textbookrush.com/browse/books/9780201734843 https://www.textbookrush.com/browse/books/9780201734843