Mail Archives: djgpp/1999/10/11/03:32:09
Mike Huang wrote:
>
> #include <vector>
>
> class matrix {
> public:
> int col, row;
> public:
> //2-D array, p836, Stroustrup, The C++ programming language, 3rd Ed.
>
> vector <vector <float> > M;
> matrix();
> matrix(int numrow, int numcol);
> ~matrix();
> matrix operator* (const matrix&, const matrix&);
> };
>
> #endif _MTX_H
>
> but when I compile it with gcc -c mtx.cpp, DJGPP gave me:
>
> mtx.h:18 'matrix::operator *(const matrix&, const matrix&)' must take
> either zero or one argument)
>
> I would like to code it so it will work like matrix1 = matrix2 *
> matrix3.
> What's wrong with my code?
Multiplication ('*') is a binary oprator. You can overloaded it with a
stand alone function with two arguments, or you can overload it with a
member function with one argument. When you overload it with a member
function, the object itself it passed in as the first argument.
--
Weiqi Gao
weiqigao AT a DOT crl DOT com
- Raw text -