Article View: gnu.g++
Article #60friend function and derived class
From: Naoki Saito (GEO-002) Ext. 5471
Date: Fri, 21 Jul 1989 21:52
Date: Fri, 21 Jul 1989 21:52
31 lines
1521 bytes
1521 bytes
Let me explain with the actual example. Suppose we have a Complex
class as in the libg++. I want to create a Complex matrix class whose element
consists of Complex. Then I want to define conjugate function of the Complex
matrix class as well as the Complex class:
In Complex.h,
friend Complex conj(Complex& z);
In ComplexMatrix.h,
friend ComplexMatrix conj(ComplexMatrix& Z);
I want to use the conj function of the Complex class in the definition of the
ComplexMatrix's conj as follows:
for (i = 0; i < rows; i++)
for (j = 0; j < cols; j++)
ZC.buf[i][j] = conj(ZC.buf[i][j]);
However, this does not work. If I use Complex::conj(ZC.buf[i][j]), this
doesn't work either because conj is not a member function of Complex class!!
So the only way I found so far is to give a different name such as "Conj" for
ComplexMatrix class. (I appreciate that UNIX system discriminate upper and
lower letters!!) Is there really no way to use the same name "conj" in the
above context?
Thanks in advance,
Naoki Saito (saito@sdr.slb.com)
Schlumberger-Doll Research
Technical Details
Message-ID:
<8907212152.AA13001@slcs.SLCS.SLB.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!sdrvx1.sinet.slb.com!saitoShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!sdrvx1.sinet.slb.com!saito From: saito@sdrvx1.sinet.slb.com (Naoki Saito (GEO-002) Ext. 5471) Newsgroups: gnu.g++ Subject: friend function and derived class Message-ID: <8907212152.AA13001@slcs.SLCS.SLB.COM> Date: 21 Jul 89 21:52:54 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 31