I am in the process of building a matrix class (uni project, with my choice of programming language) and appear to have run into a problem that I'm not too sure how to fix.

My class uses templates to define the shape of the matrix, although I'm not sure if that matters. As part of my class, I included a opEquals, but when I try to assert that a matrix created by multiplying with the identity matrix matches the output (I checked with liberal writeln()s to make sure they do) but my opEquals() function (I moved it out of the class as I kept getting errors saying it was supposed to be non-const, and couldn't figure out how to fix that either) just isn't called.

---

Matrix code (the only bit of the class used by opEquals):

```
class Matrix(size_t X, size_t Y = X){
    const size_t x_length = X;
    const size_t y_length = Y;

    double[X*Y] data;

    ...
}
```

The entirety of opEquals:

```
/// both matrices have to have an identical shape to compare
/// each element must be identical to match
bool opEquals(size_t X, size_t Y)(const Matrix!(X,Y) m1, const Matrix!(X,Y) m2) { for (int i = 0; i < m1.data.length; ++i) if (m1.data[i] != m2.data[i]) return false;
    return true;
}
```

and the code that excepts:

```
    void main() {
        auto m = new Matrix!(2)();
        m.data = [1.0,0.0,0.0,1.0].dup;
        auto n = new Matrix!(2)();
        n.data = [2.0,3.0,4.0,5.0].dup;

        auto u = mult(m,n);
        writeln("u.data vs n.data:");
        for (int i = 0; i < u.data.length; ++i)
            writeln(u.data[i], "\t", n.data[i]);


// using opEquals() directly is working, but it doesn't seem to be being used //assert(opEquals(u,n),"\"opEquals(u, n)\" is failing."); // this works fine assert(u == n,"\"u == n\" is failing."); // this fails. Why?
    }
```

---

Any help would be very much appreciated. A way to figure out what the '==' is converting its arguments to would also be great, but I'm not sure it exists (beyond just sitting down and trying to work it out myself, of course)

Reply via email to