struct vs class for small math types?

Mike Parker aldacron71 at yahoo.com
Tue Oct 24 18:49:37 PDT 2006


Bill Baxter wrote:
> 
> However, for example, with 4 doubles in a quaternion we're talking 32 
> bytes for just one of those guys.  Normally in C++ I would write 
> operator overloads and such using 'const quat&' as the argument type to 
> avoid copying the data on the stack.  Is there a way to do that in D? 

Use inout arg types. Doesn't give you const, but gives you reference 
semantics:

void func(inout MyStruct ms)
{
    ms.x = 10;
    ms.y = 20;
}

void main()
{
    MyStruct ms;
    func(ms);
    writefln(ms.x, ", ", ms.y);
}



More information about the Digitalmars-d-learn mailing list