Allocating delegate on heap?

Kirk McDonald kirklin.mcdonald at gmail.com
Mon Feb 19 04:21:53 PST 2007


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. :-)

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

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org


More information about the Digitalmars-d-learn mailing list