Hello again,

Both methods work as long as the object I call the mixin within is a struct

struct Test {
  mixin MakeMethod!("bark");
}

If I switch struct to class

class Test {
  mixin MakeMethod!("bark");
}

it segfaults.

What am I missing?



On Tuesday, 21 February 2012 at 15:29:49 UTC, Vladimir Panteleev wrote:
On Tuesday, 21 February 2012 at 14:53:06 UTC, Robert Rouse wrote:
Using a mixin, is it possible to have it define a method based on a string passed into the mixin?

A simpler way:

mixin template MakeMethod(string name)
{
        void _MakeMethod_method() { /* ... */ }
        mixin("alias _MakeMethod_method " ~ name ~ ";");
}


Reply via email to