473,486 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Operator overloading - lhs, rhs?

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
5 6126
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

<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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2558
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class,...
34
6402
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
16
3050
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
2
2042
by: pmatos | last post by:
Hi all, I'm overloading operator<< for a lot of classes. The question is about style. I define in each class header the prototype of the overloading as a friend. Now, where should I define the...
67
8571
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used...
3
2265
by: karthik | last post by:
The * operator behaves in 2 different ways. It is used as the value at address operator as well as the multiplication operator. Does this mean * is overloaded in c?
5
3602
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), ,...
3
3248
by: y-man | last post by:
Hi, I am trying to get an overloaded operator to work inside the class it works on. The situation is something like this: main.cc: #include "object.hh" #include "somefile.hh" object obj,...
9
3471
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by...
8
2948
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.