[Issue 14033] runtime error about "auto ptr = cast(T*)buf" , T is class type

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Jan 23 16:43:26 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14033

--- Comment #3 from mzfhhhh at foxmail.com ---
i see,class and struct,their memory model is different,thanks.


struct stTest
{
    int a;
    int b;

    void foo(){}
}
class clsTest
{
    int a;
    int b;

    void foo(){}
}

void main()
{
    int [100] buf  ;

    auto stPtr = cast(stTest*)buf;
    stPtr.a = 123;//ok
    stPtr.foo();//ok

    auto clsPtr = cast(clsTest)&buf;
    clsPtr.a = 123;//ok
    clsPtr.foo();//run time error,vfptr is not be assigned.
}

--


More information about the Digitalmars-d-bugs mailing list