delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/03/17:32:44

From: Chris Mangum and Savanna Judd <sneeches AT cruzio DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: C++ class interaction and overloading (should be simple answer)
Date: Sun, 03 Aug 1997 08:02:49 -0700
Organization: Cruzio Community Networking Service
Lines: 24
Message-ID: <33E49D99.6C14@cruzio.com>
References: <33E3B107 DOT 63DEA07F AT execulink DOT com>
NNTP-Posting-Host: tech10.cruzio.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jeff Weeks wrote:
> 
> 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?<Code Snipped>
>     inline friend Vector operator * (Matrix& mat, Vector& vect);<More Code Snipped>

I believe your problem here is just the order of the operands.  The first parameter in 
the overload function always corresponds to the left-most operand, and the second 
parameter is the right operand.  Thus, with your class declaration, I believe that

Vector2 = Matrix1 * Vector1

would work.  In order to get it to work the other way, with the operands in the original 
order, I believe you'll have to add a second operator* member with the paramaters as 
(Vector& vect, Matrix& mat)

-Chris Mangum
-sneeches AT cruzio DOT com

- Raw text -


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