Operator overloading - lhs, rhs?

Discussion in 'C++' started by Guest, Jan 31, 2006.

  1. Guest

    Guest Guest

    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!
    Guest, Jan 31, 2006
    #1
    1. Advertising

  2. Guest

    Rolf Magnus Guest

    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;
    }
    Rolf Magnus, Jan 31, 2006
    #2
    1. Advertising

  3. Guest

    Howard Guest

    <dontspam@_dylan_.gov> wrote in message
    news:drmpfp$1o8s$...
    > 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
    Howard, Jan 31, 2006
    #3
  4. Guest

    JustBoo Guest

    On Tue, 31 Jan 2006 17:19:05 GMT, "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?


    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. :)
    JustBoo, Jan 31, 2006
    #4
  5. Guest

    Kai-Uwe Bux Guest

    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
    Kai-Uwe Bux, Jan 31, 2006
    #5
  6. Guest

    Kai-Uwe Bux Guest

    JustBoo wrote:

    > On Tue, 31 Jan 2006 17:19:05 GMT, "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?

    >
    > Would this be a "Determinant"?


    Nope, it would just be another matrix.


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Jan 31, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    1
    Views:
    455
    Luke Meyers
    Jan 31, 2006
  2. bbrady
    Replies:
    2
    Views:
    949
    bbrady
    Jan 27, 2010
  3. fl
    Replies:
    10
    Views:
    438
    Juha Nieminen
    Jan 12, 2012
  4. Mr P
    Replies:
    21
    Views:
    203
    Brian McCauley
    Dec 28, 2005
  5. PerlFAQ Server
    Replies:
    0
    Views:
    304
    PerlFAQ Server
    Feb 8, 2011
Loading...

Share This Page