Passing shared delegates
Maxim Fomin
maxim at maxim-fomin.ru
Wed Jan 16 13:53:12 PST 2013
On Wednesday, 16 January 2013 at 20:05:40 UTC, Martin Drasar
wrote:
> Okay, I have hit another thing when dealing with shared
> delegates.
>
> If I uncomment that line I get this error:
>
>> Error: function main.B.execute (void delegate(B b) shared c)
>> is not callable using argument types (void delegate(B b)
>> shared) shared
>
> This error probably appears because typeof b is B and typeof _b
> is
> shared(B). My question is - why? Is it a bug or does the shared
> delegate
> made it shared and it is ok? And what to do with it? I can cast
> away
> shared of _b, but is it a correct and clean way?
>
> Thanks for your input.
>
> Martin
Yes, it happens so (shared function made it a member). Casting
away shared is UB but it can be done if your are sure.
Consider rewriting the code and eliminating unnecessary shareds
and please stop attaching "> " to each line of code.
To workaround add another method:
void callback(B b)
{
_b.execute(&callback);
}
More information about the Digitalmars-d-learn
mailing list