Array operations with array of structs
Peter via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 7 04:09:52 PDT 2015
On Monday, 6 July 2015 at 15:48:28 UTC, anonymous wrote:
Ok, I disabled everything in the struct except what I posted and
it ran.
I then uncommented stuff to isolate the cause. I've added in the
bits that cause the error below (plus some constructors just for
reference).
struct Vector3 {
public double[3] _p;
@nogc this(in double[] p)
{
switch ( p.length ) {
case 0: _p[0] = _p[1] = _p[2] = 0.0; break;
case 1: _p[0] = p[0]; _p[1] = _p[2] = 0.0; break;
case 2: _p[0] = p[0]; _p[1] = p[1]; _p[2] = 0.0; break;
default: _p[0] = p[0]; _p[1] = p[1]; _p[2] = p[2]; break;
}
}
@nogc this(in double p0, in double p1=0.0, in double p2=0.0)
{
_p[0] = p0;
_p[1] = p1;
_p[2] = p2;
}
@nogc this(in Vector3 other)
{
_p[] = other._p[];
}
//...
Vector3 opBinary(string op)(in Vector3 rhs) const
if (op == "+"){
Vector3 result;
result._p[] = this._p[] + rhs._p[];
return result;
}
// The bits that cause the error:
//... Enabling any one (or more) of the following causes the
error
this(this)
{
_p = _p.dup;
}
@nogc ref Vector3 opAssign(ref Vector3 rhs)
{
_p[] = rhs._p[];
return this;
}
@nogc ref Vector3 opAssign(Vector3 rhs)
{
_p[] = rhs._p[];
return this;
}
//...
}
Any ideas about what's happening?
More information about the Digitalmars-d-learn
mailing list