I am Trying to write a Matrix calculator, and have come across a difficulty. If I have A = B*C
, then B*C
is evaluated with my overloaded operator*(const Matrix&)
, in which I need some Temporary object for my calculations. This works fine. But once I come to more complicated stuff, I need more temporary objects, and obviously I don't want to do that by hand/have a miximum.
Say i want to evaluate:
Matrix A = B*C + D*E*F + G*H;
Then operator precedence tells me, that the *
will be evaluated first. So:
Step 1) B*C -> t1
Step 2) D*E -> t2
Step 3) t2*F-> t3
Step 4) G*H -> t4
Step 5) t1+t2 -> t5
Step 6) t5+t4 -> t6
Step 7) A=t6
Is this the exact order? Or is the order non deterministic? My idea was to create A linked list, and i will check in my + and *, if the objects that are being calculated (eg. t2*F) are temporary, then I can remove them/insert appropriately.