Allocating delegate on heap?

Frits van Bommel fvbommel at
Mon Feb 19 04:10:32 PST 2007

Kirk McDonald wrote:
> [test.d]
> import std.stdio;
> void main() {
>     auto dg = new void delegate();
> }
> $ dmd test.d
> test.d(4): Error: new can only create structs, dynamic arrays or class 
> objects, not void delegate()'s

That error message is wrong, by the way. It may not work for delegates, 
but it works just fine for ints.

Does anyone know the particular reason delegates are disallowed here?
Since I knew it worked for things like ints, I assumed it worked for all 
types. I hadn't actually ever tried it though, so I was a bit surprised 
by this thread...

More information about the Digitalmars-d-learn mailing list