From: Weiqi Gao Newsgroups: comp.os.msdos.djgpp Subject: Re: operator overloading error Date: Sun, 10 Oct 1999 22:08:15 -0500 Organization: CRL Network Services Lines: 36 Message-ID: <3801549F.B8627E65@a.crl.com> References: <3801119D DOT 531FBBEC AT yahoo DOT com> NNTP-Posting-Host: a116002.stl1.as.crl.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.2.5-15 i586) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Mike Huang wrote: > > #include > > class matrix { > public: > int col, row; > public: > //2-D array, p836, Stroustrup, The C++ programming language, 3rd Ed. > > vector > 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