Newsgroups: comp.os.msdos.djgpp From: Peter Berdeklis Subject: Re: C++ class interaction and overloading (should be simple answer) Message-ID: Nntp-Posting-Host: chinook.physics.utoronto.ca Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator) Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: University of Toronto - Dept. of Physics In-Reply-To: <5s3l9f$o46@freenet-news.carleton.ca> Date: Tue, 5 Aug 1997 15:27:07 GMT References: <33E3B107 DOT 63DEA07F AT execulink DOT com> <5s3l9f$o46 AT freenet-news DOT carleton DOT ca> Lines: 46 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On 4 Aug 1997, Paul Derbyshire wrote: > > Jeff Weeks (pweeks AT execulink DOT com) writes: > > 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); > > Try omitting the space after "operator": > > inline friend Vector operator* (Matrix& mat, Vector& vect); > ^^ Not quite Paul. As Eric said in another followup, this is perfectly legal. The problem is with the order of your arguments. You have defined Matrix * Vector but are asking for Vector * Matrix Unless there is a defined cast from Matrix to Vector and from Vector to Matrix, the compiler won't be able to find a match, because switching the order of the arguments is illegal. Either always call Vector * Matrix, or define both. The one could be just an inline which calls the other with the arguments reversed. --------------- Peter Berdeklis Dept. of Physics, Univ. of Toronto