Thread View: gnu.g++
1 messages
1 total messages
Started by Naoki Saito (GEO-002) Ext. 5471
Fri, 21 Jul 1989 21:52
friend function and derived class
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads