Mail Archives: djgpp/1997/08/05/13:35:35
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
- Raw text -