Return a class instance as a pointer

simendsjo simendsjo at gmail.com
Sat Mar 31 08:28:57 PDT 2012


On Sat, 31 Mar 2012 17:02:43 +0200, Timo Westkämper  
<timo.westkamper at gmail.com> wrote:

> I am trying to compile the following code in D
>
> void* instantiate(_LV2_Descriptor* descriptor,
>    double sample_rate, char * bundle_path,
>    LV2_Feature** features) {
>    Plugin plugin = new Bleep(sample_rate, features);
>    return &plugin;
> }
>
> but I get the following error
>
> ../src/lv2/plugin.d(38): Error: escaping reference to local plugin
>
> What is the right way to create a class instance and a return it as a  
> pointer? Also in such a way that it is not claimed by GC. There is  
> another callback for object deletion.
>

try
return cast(void*)new Bleep(sample_rate, features);


More information about the Digitalmars-d mailing list