Return a class instance as a pointer
Timo Westkämper" <timo.westkamper at gmail.com>
Timo Westkämper" <timo.westkamper at gmail.com>
Sat Mar 31 08:32:14 PDT 2012
On Saturday, 31 March 2012 at 15:29:15 UTC, Jacob Carlborg wrote:
> On 2012-03-31 17:02, "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.
>
> Why would you want to return an object as a pointer? All
> classes are reference types. But if you actually do want to
> return an object as a pointer you can just cast it to void*.
I am writing a D binding for the LV2 audio plugin API. The
instantiate function expects a void* return. I wouldn't use void*
casts in D code which doesn't interface with C.
The cast worked, thanks.
More information about the Digitalmars-d
mailing list