Template for function or delegate (nothing else)

useo useo at start.bg
Wed Feb 9 13:34:04 PST 2011


== Auszug aus Steven Schveighoffer (schveiguy at yahoo.com)'s Artikel
> On Wed, 09 Feb 2011 16:14:04 -0500, useo <useo at start.bg> wrote:
> > I just have a problem with my variables.
> >
> > For example... my class/template just looks like:
> >
> > class Example(T) if (is(T == delegate) || is(T == function))
> > {
> >    T callback;
> >
> >    void setCallback(T cb) {
> >       callback = cb;
> >    }
> >
> > }
> >
> > This means that I need variables like Example!(void function())
> > myVariable. But is there any possibility to use variables like
> > Example myVariable? The template declaration only defines the
type of
> > a callback and perhaps one method-declaration nothing else. I
already
> > tried Example!(void*) because delegates and functions are void
> > pointers but I always get an error. I hope there is any way to do
> > this.
> If I understand you correctly, you don't want to declare the type
of T
> when instantiating the template?  This is not possible, templates
must
> have all parameters defined at instantiation time.
> If you just want a shorter thing to type for Example!(void function
()),
> you can do:
> alias Example!(void function()) MyType;
> MyType myVariable;
> -Steve

Yes, right, I don't want declare the template-type.

Nevertheless... thanks


More information about the Digitalmars-d-learn mailing list