digitalmars.D.learn - std.signal woes :/
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?
Feb 23 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); }
Feb 23 2013
On Saturday, 23 February 2013 at 23:39:19 UTC, cal wrote:On Saturday, 23 February 2013 at 17:01:48 UTC, Damian wrote:That solution is ok for 1 argument but for many arguments it wont suffice. This is issue 5028.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); }
Feb 24 2013
On Sunday, 24 February 2013 at 17:30:14 UTC, Damian wrote:That solution is ok for 1 argument but for many arguments it wont suffice. This is issue 5028.What is the problem with many arguments? I'm probably misunderstanding, but e.g. this works: struct MySignal(T...) { mixin Signal!T _signal; alias _signal this; } class A { MySignal!(float, int[]) sigA; } class B : A { MySignal!(int, string, char) sigB; } void main() { auto a = new A; auto b = new B; a.sigA.emit(1.4, [1,2,3]); b.sigA.emit(1, [4,5,6]); b.sigB.emit(1, "hello", 'x'); }
Feb 24 2013
On Sunday, 24 February 2013 at 19:20:06 UTC, cal wrote:On Sunday, 24 February 2013 at 17:30:14 UTC, Damian wrote:Oooh I could of sworn I tried that.. it was late and I was defining MySignal as a mixin still!! My bad! Your workaround does indeed work. Thanks.That solution is ok for 1 argument but for many arguments it wont suffice. This is issue 5028.What is the problem with many arguments? I'm probably misunderstanding, but e.g. this works: struct MySignal(T...) { mixin Signal!T _signal; alias _signal this; } class A { MySignal!(float, int[]) sigA; } class B : A { MySignal!(int, string, char) sigB; } void main() { auto a = new A; auto b = new B; a.sigA.emit(1.4, [1,2,3]); b.sigA.emit(1, [4,5,6]); b.sigB.emit(1, "hello", 'x'); }
Feb 25 2013