Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Operator overloading - lhs, rhs?

Reply
Thread Tools

Operator overloading - lhs, rhs?

 
 
Guest
Posts: n/a
 
      01-31-2006
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!



 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      01-31-2006
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;
}

 
Reply With Quote
 
 
 
 
Howard
Guest
Posts: n/a
 
      01-31-2006

<dontspam@_dylan_.gov> wrote in message
news:drmpfp$1o8s$(E-Mail Removed)...
> 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


 
Reply With Quote
 
JustBoo
Guest
Posts: n/a
 
      01-31-2006
On Tue, 31 Jan 2006 17:19:05 GMT, "Howard" <(E-Mail Removed)>
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.
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      01-31-2006
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
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      01-31-2006
JustBoo wrote:

> On Tue, 31 Jan 2006 17:19:05 GMT, "Howard" <(E-Mail Removed)>
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
overloading operator->*() and operator->() gob00st@googlemail.com C++ 2 02-21-2009 04:26 AM
overloading operator->*() and operator->() gob00st@googlemail.com C++ 11 02-20-2009 08:52 PM
user defined conversion operator or operator overloading? hurcan solter C++ 3 08-29-2007 07:39 PM
Why is overloading operator. (member operator) forbidden? dascandy@gmail.com C++ 11 05-16-2007 07:54 PM
Operator overloading on "default" operator John Smith C++ 2 10-06-2004 10:22 AM



Advertisments