struct opCast to void* and back
Robert Clipsham
robert at octarineparrot.com
Sun Apr 11 06:26:53 PDT 2010
On 11/04/10 12:47, Nrgyzer wrote:
>> Try *cast(MyStruct*). In opCast you are returning&this, which is of
>> type MyStruct* until it is implicitly cast to void*. In the writefln()
>> you then cast it back to MyStruct*, and dereference it so you can use
>> it. In your version you are trying to cast from a pointer to the struct
>> to the actual struct, which is why it doesn't work.
>
> By using *cast(MyStruct*) I get the following message: "Error: 1invalid UTF-8 sequence"
I don't know how writefln() works in D1 (I presume that's what you're
using), but try the following:
writefln( "%s", (*cast(MyStruct*)temp).toString() );
I don't have a D1/Phobos compiler available to me to test, so I don't
know if that will help. You usually get that error when trying to print
/use strings with invalid UTF sequences in them, which looking at your
program, shouldn't be happening. If you're using code other than what
you're showing that could be it.
More information about the Digitalmars-d
mailing list