Dispatching from receive to a function

Bob Cowdery bob at bobcowdery.plus.com
Mon Sep 27 06:36:35 PDT 2010


 Thanks. Do you know if the signature is a mandatory part. If I left the
signature out would it then only work with a delegate with no
parameters? If so I think I'm in the same state as my delegates will not
all have the same signature.

Bob

On 27/09/2010 14:21, Johannes Pfau wrote:
> On 27.09.2010 15:07, Bob Cowdery wrote:
>> Failing that I think a dispatcher structure using an associative array
>> would be my next choice. However I'm getting stuck on how to define and
>> use an array which maps a string key to a delegate. Can someone help me
>> out there please. I will then effectively have my 'Atom' as a string in
>> the message and dispatch on that.
>>
> Not sure about the other questions, but here's an example for a
> string/delegate associative array:
> -------------------------------------------
> import std.stdio;
>
> alias bool delegate(int, char) TestDelegate;
>
> TestDelegate[string] dict;
>
> class C
> {
>     bool test(int i, char c) {return true;}
> }
>
> void main()
> {
>     C c = new C();
>     dict["test"] = &c.test;
>     writeln(dict["test"](0, 'c'));
> }
> -----------------------------------------------
>



More information about the Digitalmars-d-learn mailing list