digitalmars.D.learn - mixin template had error by calling shared function
- Vlasov Roman (34/34) Dec 10 2014 I have this code
- Rikki Cattermole (6/39) Dec 10 2014 Ugh, that's a compiler bug.
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (5/60) Dec 10 2014 Better yet, try this:
- Vlasov Roman (5/67) Dec 10 2014 I tried this, but compiler give me error
- Rikki Cattermole (6/71) Dec 10 2014 This is why I didn't suggest this myself.
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (1/1) Dec 10 2014 https://issues.dlang.org/show_bug.cgi?id=13850
- Dan Olson (6/10) Dec 11 2014 mixin template Template(alias func1, alias func2)
I have this code import std.stdio; mixin template Template(void function() func1, void function() func2) { void to() { func1(); func2(); } }; class SomeClass { mixin Template!(&func, &func23); void func() { writeln("First function!"); } void func23() { writeln("First function!"); } void toTemplate() { to(); } } void main() { SomeClass a = new SomeClass(); a.toTemplate(); } After running the program give me SIGSEGV in func23(); Terminal with gdb: Program received signal SIGSEGV, Segmentation fault. 0x0000000000428352 in invariant._d_invariant(Object) () (gdb) up Manjaro Linux 0.9.0 x86_64 dmd 2.066 Kernel 3.14.4
Dec 10 2014
On 10/12/2014 10:10 p.m., Vlasov Roman wrote:I have this code import std.stdio; mixin template Template(void function() func1, void function() func2) { void to() { func1(); func2(); } }; class SomeClass { mixin Template!(&func, &func23); void func() { writeln("First function!"); } void func23() { writeln("First function!"); } void toTemplate() { to(); } } void main() { SomeClass a = new SomeClass(); a.toTemplate(); } After running the program give me SIGSEGV in func23(); Terminal with gdb: Program received signal SIGSEGV, Segmentation fault. 0x0000000000428352 in invariant._d_invariant(Object) () (gdb) up Manjaro Linux 0.9.0 x86_64 dmd 2.066 Kernel 3.14.4Ugh, that's a compiler bug. You should not be able to pass in delegates as function pointers to a mixin template. A better way would be to pass in the names of the methods into the mixin template and then use string mixin's to call the methods.
Dec 10 2014
On Wednesday, 10 December 2014 at 09:41:43 UTC, Rikki Cattermole wrote:On 10/12/2014 10:10 p.m., Vlasov Roman wrote:Better yet, try this: mixin template Template(void delegate() func1, void delegate() func2)I have this code import std.stdio; mixin template Template(void function() func1, void function() func2) { void to() { func1(); func2(); } }; class SomeClass { mixin Template!(&func, &func23); void func() { writeln("First function!"); } void func23() { writeln("First function!"); } void toTemplate() { to(); } } void main() { SomeClass a = new SomeClass(); a.toTemplate(); } After running the program give me SIGSEGV in func23(); Terminal with gdb: Program received signal SIGSEGV, Segmentation fault. 0x0000000000428352 in invariant._d_invariant(Object) () (gdb) up Manjaro Linux 0.9.0 x86_64 dmd 2.066 Kernel 3.14.4Ugh, that's a compiler bug. You should not be able to pass in delegates as function pointers to a mixin template. A better way would be to pass in the names of the methods into the mixin template and then use string mixin's to call the methods.
Dec 10 2014
On Wednesday, 10 December 2014 at 10:34:25 UTC, Marc Schütz wrote:On Wednesday, 10 December 2014 at 09:41:43 UTC, Rikki Cattermole wrote:I tried this, but compiler give me error main.d(12): Error: no 'this' to create delegate for func main.d(12): Error: no 'this' to create delegate for func23 I think that error because i don't completly know dlangOn 10/12/2014 10:10 p.m., Vlasov Roman wrote:Better yet, try this: mixin template Template(void delegate() func1, void delegate() func2)I have this code import std.stdio; mixin template Template(void function() func1, void function() func2) { void to() { func1(); func2(); } }; class SomeClass { mixin Template!(&func, &func23); void func() { writeln("First function!"); } void func23() { writeln("First function!"); } void toTemplate() { to(); } } void main() { SomeClass a = new SomeClass(); a.toTemplate(); } After running the program give me SIGSEGV in func23(); Terminal with gdb: Program received signal SIGSEGV, Segmentation fault. 0x0000000000428352 in invariant._d_invariant(Object) () (gdb) up Manjaro Linux 0.9.0 x86_64 dmd 2.066 Kernel 3.14.4Ugh, that's a compiler bug. You should not be able to pass in delegates as function pointers to a mixin template. A better way would be to pass in the names of the methods into the mixin template and then use string mixin's to call the methods.
Dec 10 2014
On 11/12/2014 12:24 a.m., Vlasov Roman wrote:On Wednesday, 10 December 2014 at 10:34:25 UTC, Marc Schütz wrote:This is why I didn't suggest this myself. Basically you are trying to take a pointer to a function that takes an argument (this). But a delegate is not exactly that. A delegate is a function pointer + this pointer as well. Essentially you can't do this for a type.On Wednesday, 10 December 2014 at 09:41:43 UTC, Rikki Cattermole wrote:I tried this, but compiler give me error main.d(12): Error: no 'this' to create delegate for func main.d(12): Error: no 'this' to create delegate for func23 I think that error because i don't completly know dlangOn 10/12/2014 10:10 p.m., Vlasov Roman wrote:Better yet, try this: mixin template Template(void delegate() func1, void delegate() func2)I have this code import std.stdio; mixin template Template(void function() func1, void function() func2) { void to() { func1(); func2(); } }; class SomeClass { mixin Template!(&func, &func23); void func() { writeln("First function!"); } void func23() { writeln("First function!"); } void toTemplate() { to(); } } void main() { SomeClass a = new SomeClass(); a.toTemplate(); } After running the program give me SIGSEGV in func23(); Terminal with gdb: Program received signal SIGSEGV, Segmentation fault. 0x0000000000428352 in invariant._d_invariant(Object) () (gdb) up Manjaro Linux 0.9.0 x86_64 dmd 2.066 Kernel 3.14.4Ugh, that's a compiler bug. You should not be able to pass in delegates as function pointers to a mixin template. A better way would be to pass in the names of the methods into the mixin template and then use string mixin's to call the methods.
Dec 10 2014
https://issues.dlang.org/show_bug.cgi?id=13850
Dec 10 2014
Here is a way that will work. "Vlasov Roman" <vlasovroman.ru yandex.ru> writes:I have this code mixin template Template(void function() func1, void function() func2)mixin template Template(alias func1, alias func2)class SomeClass { mixin Template!(&func, &func23);mixin Template!(func, func23); -- dano
Dec 11 2014