By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,954 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,954 IT Pros & Developers. It's quick & easy.

Operator overloading - lhs, rhs?

P: n/a
Hi all,

I have a function:

mat4 operator * (const float scalar);

(matrix times integer)

Is there a way that I could multiply an int by a matrix, as opposed to only a matrix by an int?
Thanks!

Jan 31 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
dontspam@_dylan_.gov wrote:
Hi all,

I have a function:

mat4 operator * (const float scalar);
I guess this is a member?
(matrix times integer)

Is there a way that I could multiply an int by a matrix, as opposed to
only a matrix by an int?


Yes, make it a non-member.

mat4 operator*(float scalar, const mat4& mat)
{
return mat * scalar;
}

Jan 31 '06 #2

P: n/a

<dontspam@_dylan_.gov> wrote in message
news:dr***********@bigboote.WPI.EDU...
Hi all,

I have a function:

mat4 operator * (const float scalar);

(matrix times integer)

Is there a way that I could multiply an int by a matrix, as opposed to
only a matrix by an int?


You could make it a non-member.

But I'm curious as to what it would do...? I know that the result of
multiplying a matrix by a scaler is another matrix, but what would the
result of multiplying the other way around be?

If the result you want is a matrix (which is the only thing that makes sense
to me), then why do you need a specific order? Can't you just re-order the
call?

Oh well, in any case, the answer is to make it a non-member, and pass both
the integer scaler (lhs) and the matrix (rhs) as parameters.

-Howard
Jan 31 '06 #3

P: n/a
On Tue, 31 Jan 2006 17:19:05 GMT, "Howard" <al*****@hotmail.com>
wrote:
But I'm curious as to what it would do...? I know that the result of
multiplying a matrix by a scaler is another matrix, but what would the
result of multiplying the other way around be?


Would this be a "Determinant"?

http://en.wikipedia.org/wiki/Determinant

http://mathworld.wolfram.com/Determinant.html

I am an ANTHROPOMORPHIC PERSONIFICATION
of... Um, whatever a mathematician is not.... iow, I'm
not a mathematician. :-)
Jan 31 '06 #4

P: n/a
Howard wrote:

But I'm curious as to what it would do...? I know that the result of
multiplying a matrix by a scaler is another matrix, but what would the
result of multiplying the other way around be?
Actually, by convention, the scalar *should* be on the left, i.e, it
*should* read cA, where c is a scalar and A is a matrix. The result would
be a matrix. However, since fields are commutative, there is no real
difference between a left- and a right-vector space. In other words, you
can put the scalar on either side of the matrix, the product is always just
a matrix.
If the result you want is a matrix (which is the only thing that makes
sense to me),
It's not just you :-)
then why do you need a specific order? Can't you just re-order
the call?
Sounds fine.
Oh well, in any case, the answer is to make it a non-member, and pass both
the integer scaler (lhs) and the matrix (rhs) as parameters.

Best

Kai-Uwe Bux
Jan 31 '06 #5

P: n/a
JustBoo wrote:
On Tue, 31 Jan 2006 17:19:05 GMT, "Howard" <al*****@hotmail.com>
wrote:
But I'm curious as to what it would do...? I know that the result of
multiplying a matrix by a scaler is another matrix, but what would the
result of multiplying the other way around be?


Would this be a "Determinant"?


Nope, it would just be another matrix.
Best

Kai-Uwe Bux
Feb 1 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.