import std.conv : to; struct Matrix(T, size_t r, size_t c){
public: T[r*c] _data; Matrix opBinary(string op)(T scalar) if(op == "*"){ string construct(){ string result = "["; for(size_t i = 0; i < r * c; i++) result ~= "_data["~to!string(i)~"] * scalar, "; return result ~= "]"; } return Matrix(mixin(construct())); } Matrix opBinary(string op)(ref const(Matrix) m) const if(op == "+" || op == "-"){ string construct(){ string result = "["; for(size_t i = 0; i < r * c; i++) result ~= "_data["~to!string(i)~"]"~op~"m._data["~to!string(i)~"], "; return result ~= "]"; } return Matrix(mixin(construct())); } } struct A(T){ public: Matrix!(T, 3, 1) _a; alias _a this; this(T a, T b, T c){ this._data[0] = a; this._data[1] = b; this._data[2] = c; } } void main(){ auto a = A!double(3, 3, 3); auto r1 = a * 3.0; // ok auto r2 = a + a; // ok auto r3 = a + (a * 3.0); // Error: incompatible types for ((a) + (a._a.opBinary(3.0e+0))): 'A!(double)' and 'Matrix!(double,3,1)' } Why does the last expression fail? and how do I fix it?