[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can specializations of a template class be mutual friends ?
From: |
Michael D. Berger & Rosalie A. Clavez |
Subject: |
Re: How can specializations of a template class be mutual friends ? |
Date: |
Fri, 09 Mar 2001 17:38:16 -0800 |
Please modify as I have indicated below and let me know if it works.
I would like to know this myself. I have never before seen attempts to
refer to template instantiations within the template itself.
Thanks,
Mike.
Ulf Rehmann wrote:
>
> 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>;
friend class complex;
> };
> 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
>
> _______________________________________________
> Help-gplusplus mailing list
> Help-gplusplus@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-gplusplus
--
Michael D. Berger
Rosalie A. Clavez
m.d.berger@ieee.org