Reset all Members of a Aggregate Instance

Marc Schütz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 8 03:07:27 PST 2015


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`.


More information about the Digitalmars-d-learn mailing list