Putting function pointers / delegates into associative array.

visitor visitor at gmail.com
Thu Jan 4 02:34:55 UTC 2018


On Thursday, 4 January 2018 at 01:40:21 UTC, Mark wrote:
> What I'm trying to do here is to be able to call a function 
> based off of a key.
>


class tester {

	private void delegate() [char] funcs;

	this() {
		funcs = ['a': &A, 'b': &B];
	}

	public void callFuncs(char a) {
		funcs[a]();
	}

	private void A() {
		writeln("A");
	}

	private void B() {
		writeln("B");
	}
}




More information about the Digitalmars-d-learn mailing list