Re: Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
Nevermind.. I had it as struct playing around and didn't change it back On Tuesday, 21 February 2012 at 18:37:02 UTC, Robert Rouse wrote: I did not. Trying to new it gives me a compile error since "MyClass a" is not a pointer. If I define another method without mixin and call it before the

Re: Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
I did not. Trying to new it gives me a compile error since "MyClass a" is not a pointer. If I define another method without mixin and call it before the "mixin" one, it works. On Tuesday, 21 February 2012 at 18:13:30 UTC, Adam D. Ruppe wrote: On Tuesday, 21 February 2012 at 18:07:34 UTC, R

Re: Naming methods from strings using mixin

2012-02-21 Thread Adam D. Ruppe
On Tuesday, 21 February 2012 at 18:07:34 UTC, Robert Rouse wrote: What am I missing? Did you remember to new the class? class MyClass {} MyClass a; // a is null right now a = new MyClass(); // gotta remember this That's different than structs (or classes in C++) which work without being ne

Re: Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
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, Vl

Re: Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
Awesome. Thanks! Adam D. Ruppe 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? Yeah, though you'll have to build a string of the method. Something like this: string

Re: Naming methods from strings using mixin

2012-02-21 Thread Vladimir Panteleev
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 _Make

Re: Naming methods from strings using mixin

2012-02-21 Thread Adam D. Ruppe
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? Yeah, though you'll have to build a string of the method. Something like this: string make_method_string(string name) { strin

Naming methods from strings using mixin

2012-02-21 Thread Robert Rouse
Using a mixin, is it possible to have it define a method based on a string passed into the mixin? An example of what I'm hoping to do: mixin template make_method(string name) { void name() { // not sure how to make it become "void bark()" here writeln("hello"); } } class Ani