std.signal woes :/

cal callumenator at gmail.com
Sat Feb 23 15:39:18 PST 2013


On Saturday, 23 February 2013 at 17:01:48 UTC, Damian wrote:
> Ok signals work fine, until I use them in a descendant class.
>
> Snippet:
> -----------------
> import std.signals;
>
> class ClassA
> {
> 	public mixin Signal!(int) addNumber1;
> }
>
> class ClassB : ClassA
> {
> 	public mixin Signal!(int) addNumber2;
> }
>
> Error:
> \dmd2\src\phobos\std\signals.d(0,0): Error: function 
> main.ClassB.Signal!(int).emit cannot override final function 
> main.ClassA.Signal!(int).emit (moooo)
>
>
> Is this expected behavior or a bug in my code?

I think this is a known issue. Here is a workaround I've used:


import std.signals;

struct MySignal(T)
{
     mixin Signal!T _signal;
     alias _signal this;
}

class ClassA
{
     MySignal!int addNumber1;
}

class ClassB : ClassA
{
     MySignal!int addNumber2;
}

void main()
{
     auto a = new ClassA;
     auto b = new ClassB;
     a.addNumber1.emit(1);
     b.addNumber1.emit(1);
     b.addNumber2.emit(1);
}



More information about the Digitalmars-d-learn mailing list