delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/05/20:04:32

From: Jeff Weeks <pweeks AT execulink DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: C++ class interaction and overloading (should be simple answer)
Date: Sat, 02 Aug 1997 18:13:27 -0400
Organization: Code X Software
Lines: 58
Message-ID: <33E3B107.63DEA07F@execulink.com>
NNTP-Posting-Host: ppp35.neptune.execulink.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi there...

I've got a C++ problem here.  I've defined a two classes: Vector and
Matrix.  I'd like to be able to do this:

Vector2 = Vector1 * Matrix1

But I can't get that to work.  Is this possible?

What I tried was this (in my Vector class):

class Vector {
  ...
  public:
    inline friend Vector operator * (Matrix& mat, Vector& vect);
  ...
};

inline Vector operator * (Matrix& mat, Vector& vect) {
  Vector v;

  v.x = vect.x * mat.get(0,0) +
        vect.y * mat.get(1,0) +
        vect.z * mat.get(2,0) +
                 mat.get(3,0);

  v.y = vect.x * mat.get(0,1) +
        vect.y * mat.get(1,1) +
        vect.z * mat.get(2,1) +
                 mat.get(3,1);

  v.z = vect.x * mat.get(0,2) +
        vect.y * mat.get(1,2) +
        vect.z * mat.get(2,2) +
                 mat.get(3,2);

  return v;
}
 
I'm afraid I can't remember the error I got (and I'm in Linux now so I
can't check...).  It was something along the lines of, "Can't find
operator to math that expression" :)

I'd really like to get that working, so if anybody has any information
on this, please do tell.  If you need more information, I'll do my best
to supply it.

Thanks a lot,
Jeff


--------------------------------------------
            - Code X Software -
       Programming to a Higher Power
  
  email: mailto:pweeks AT execulink DOT com
  web:	 http://www.execulink.com/~pweeks/
--------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019