mixin template had error by calling shared function
Vlasov Roman via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Dec 10 03:24:11 PST 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:
>> 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
>>> #1 0x00000000004257f7 in main.SomeClass.func23() ()
>>>
>>>
>>> Manjaro Linux 0.9.0 x86_64
>>> dmd 2.066
>>> Kernel 3.14.4
>>
>> Ugh, 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.
>
> Better yet, try this:
>
> mixin template Template(void delegate() func1, void delegate()
> func2)
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 dlang
More information about the Digitalmars-d-learn
mailing list