Hello,

I have several classes, similar to vectors and matrices, that need to be able to mulitply themselves in the following way.

Vector vec1;
Vector vec2;
Matrix mat1;

vec2 = vec1 * mat1 * vec2; (1)

Btw this is just a sample of what I want to do, I haven't worried about transpose and sizes etc. To implement this, I have written the classes to take references and return objects. For example,

Vector Matrix:perator* (const Vector&);

But as you can imagine, I can't do the sum (1) above because the return object from the first multiplication is not assigned, so a reference can't be passed to the second multiplication operation.

Is there a way to be able to do sum (1) without passing in an object rather than a reference?

2. Declare operator* to be a free function, e.g.,
Code:
`Vector operator*(const Vector&, const Vector&);`
EDIT:

Sorry, on re-reading I realised that my answer is not quite correct, partially due to my lack of knowledge of matrices and vectors (I'm from my school cohort that had the most sketchy curriculum on matrices ). So pardon me if what I ask seems obvious.

The rationale for having operator* as a free function is so that an appropriate constructor can be used to (implicitly) convert related types. In this case, however, I am not so sure if makes sense to have a Vector so easily convertible to a Matrix, and/or vice versa.

So, what does vec1 * mat1 mean? If it should return a Vector, then you can have either:
Code:
```Vector operator*(const Vector&, const Matrix&);
// or
Vector Vector::operator*(const Matrix&) const;```
On the other hand, if it returns a Matrix, then you should have:
Code:
`Matrix operator*(const Vector&, const Matrix&);`
Hope you get the idea.

3. You still want it to be a free function so you can have
Code:
`Vector operator*(const Matrix&, const Vector&);`
or whatever.