delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/11/03:32:09

From: Weiqi Gao <weiqigao AT a DOT crl DOT com>
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
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 <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 -


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