Allocating delegate on heap?

Frits van Bommel fvbommel at
Mon Feb 19 04:59:13 PST 2007

Kirk McDonald wrote:
> Frits van Bommel wrote:
>> 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...
> In my opinion, it /should/ work, but I just go by what the compiler 
> tells me. :-)

I agree, that's why I asked if there was any particular reason it didn't 
:). It seems like a very silly restriction to me.

> Even if this did work, the point about keeping local references to 
> GC-controlled data remains.

I didn't comment on that, did I?

More information about the Digitalmars-d-learn mailing list