opDispatch doesn't play nice with inheritance

Carl Sturtivant sturtivant at gmail.com
Thu Nov 15 18:33:27 UTC 2018


On Thursday, 15 November 2018 at 18:04:42 UTC, Adam D. Ruppe 
wrote:
> Right, all templates are final, including opDispatch.
>
> What I've done in the past is to forward them to a virtual 
> function with runtime arguments instead of compile time 
> arguments.
>
> Kinda like:
>
> void opDispatch(string name)() {
>      callMethod(name);
> }
>
> /* virtual */ void callMethod(string name) {
>      // do a reflection loop or associate array or switch or 
> whatever to dispatch it here, reimplemented (or at least 
> re-mixed-in) in the child classes to account for their new 
> methods
> }
>
>
>
> What exactly do you need to do with it? Maybe you can do an 
> alternative design.

Well, I found an alternative design not using opDispatch, not 
fundamentally dissimilar to what you suggested above, thanks for 
that, and it's not too uneconomical in its textual organization. 
I was hoping to avoid doing any of my own dispatching when 
inheritance would do it for me.





More information about the Digitalmars-d-learn mailing list