[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How can specializations of a template class be mutual friends ?
From: |
Ulf Rehmann |
Subject: |
How can specializations of a template class be mutual friends ? |
Date: |
Fri, 9 Mar 2001 19:07:15 +0100 |
I would like to make two specializations of the same template
mutual friends. However:
The following code gives an error under g++ 2.95.2:
template<class Scalar>
class complex{
Scalar re, im;
public:
complex(Scalar r, Scalar i) { re=r, im=i;};
template<class T>
complex(const complex<T>& c) { re=c.re; im=c.im; };
friend class complex<float>;
friend class complex<double>;
};
int main() {
complex<float> cf(0,0);
complex<double> cd = cf;
}
This is the error message:
g++ ttt.cc
ttt.cc: In method `complex<double>::complex<float>(const complex<float> &)':
ttt.cc:13: instantiated from here
ttt.cc:3: `float complex<float>::re' is private
ttt.cc:7: within this context
ttt.cc:3: `float complex<float>::im' is private
ttt.cc:7: within this context
What is wrong?
Any hint is welcome.
Ulf Rehmann
- How can specializations of a template class be mutual friends ?,
Ulf Rehmann <=