In this example, you are creating the mod_a library, so it would be relatively easy to modify it. But I cannot help but think about the situation when you are not the author of the library.
In this case, the actual author of the library will probably be happy that you cannot just do what you are trying to do ... or actively want to support what you are trying to do.
suggests that the library writer wants you to be able to “capture” the function that he uses in his implementation. He or she will probably go differently; I would do.
This is one of the areas where I believe that the encapsulation stories that you linked, and I just read, accurately describes how to achieve the opposite situation of what you want here. This type screams that he needs contract programming.
As the author of the library, I would probably offer you an interface and, possibly, an abstract class, perhaps one or two specific implementations that you could use to accomplish your task. Someone else might add a template or runtime parameter that requires a specific implementation as an argument. However, someone else might add a lazy line delegate to the mix.
(my) conclusion: as the author of the library, there are options to do what you want. If this is not possible with your preferred library, you are likely to finish submitting the function request.
Kris
source share