December 08, 2015 Re: Reset all Members of a Aggregate Instance | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Wright | On Tuesday, 8 December 2015 at 05:13:51 UTC, Chris Wright wrote:
> On Tue, 08 Dec 2015 14:12:02 +1100, Daniel Murphy wrote:
>
>> On 4/12/2015 8:38 AM, Chris Wright wrote:
>>> An object reference is just a pointer, but we can't directly cast it. So we make a pointer to it and cast that; the type system allows it. Now we can access the data that the object reference refers to directly.
>>
>> Casting is fine too: cast(void*)classRef
>
> Amazing. I assumed that this wouldn't be allowed because it's not exactly nice to the type system, but apparently you can cast anything but a user- defined value type to void*. Bool, dchar, associative arrays, normal arrays, the good void* casts them all.
A class can theoretically overload `opCast`. Therefore, to be 100% sure it works in all cases, you should use `*cast(void**) &classRef`.
|
Copyright © 1999-2021 by the D Language Foundation