Topic: Can a friend be a template function?
Author: Alex Vinokur <alexander.vinokur@telrad.co.il>
Date: 1999/06/15 Raw View
In article <929123754.943760@iris.nyx.net>,
hrubin@nospam.net (Howard Rubin - change nospam to nyx) wrote:
> I was hoping for a way to make the template function a friend
> of the class, but since I don't know how to do that, I'm
> settling for an accessor.
>
[snip]
Here is an example.
Alex
//#########################################################
//------------------- C++ code : BEGIN -------------------
template <typename T1, typename T2, typename T3>
class FFF;
class AAA {public : AAA (); };
template <typename T1> class BBB1 {public : BBB1 (); };
template <typename T1> class BBB2 {public : BBB2 (); };
template <typename T1> class BBB3 {public : BBB3 (); };
template <typename T1, typename T2> class CCC1 {};
template <typename T1, typename T2> class CCC2 {};
template <typename T1, typename T2> class CCC3 {};
template <typename T1, typename T2> class CCC4 {};
template <typename T1, typename T2> class CCC5 {};
template <typename T1, typename T2, typename T3> class DDD1 {};
template <typename T1, typename T2, typename T3> class DDD2 {};
template <typename T1, typename T2, typename T3> class DDD3 {};
template <typename T1, typename T2, typename T3> class DDD4 {};
template <typename T1, typename T2, typename T3> class DDD5 {};
template <typename T1, typename T2, typename T3, typename T4> class EEE1
{};
template <typename T1, typename T2, typename T3>
class FFF
{
friend class AAA;
friend class BBB1<int>;
friend class BBB2<T1>;
template <typename S1> friend class BBB3<S1>;
friend class CCC1<int, float>;
friend class CCC2<int, T2>;
friend class CCC2<T1, int>;
friend class CCC3<T1, T2>;
friend class CCC3<T1, T3>;
friend class CCC3<T2, T3>;
friend class CCC3<T3, T2>;
template <typename S2> friend class CCC4<int, S2>;
template <typename S1, typename S2> friend class CCC5<S1, S2>;
friend class DDD1<int, char, float>;
friend class DDD2<int, T2, float>;
friend class DDD2<int, T3, float>;
friend class DDD3<T1, T2, T3>;
friend class DDD3<T1, T3, T2>;
template <typename S1, typename S2> friend class DDD4<T1, S2, S1>;
template <typename S1, typename S2, typename S3> friend class DDD5<S3,
S1, S2>;
template <typename S> friend class EEE1<T1, T2, S, T3>;
private :
FFF (T1 t1) {}
public :
~FFF () {}
};
AAA::AAA ()
{
FFF<int, char, float> (5);
}
template <typename T1>
BBB1<T1>::BBB1 ()
{
FFF<T1, double, float> (T1 ());
};
template <typename T1>
BBB2<T1>::BBB2 ()
{
FFF<T1, double, float> (T1 ());
};
class YYY {};
template <typename T1>
BBB3<T1>::BBB3 ()
{
FFF<YYY, double, float> (YYY ());
};
class XXX {};
int main ()
{
AAA a;
BBB1<int> b1;
BBB2<int> b2;
BBB2<char> b3;
BBB2<XXX> b4;
BBB3<XXX> b5;
return 0;
}
//------------------- C++ code : END ----------------------
//#########################################################
//------------------- Compiler & System ------------------
g++ -v : gcc version egcs-2.91.57 19980901
(egcs-1.1 release)
uname -a : SunOS <nodename> 5.6 Generic_105181-09
sun4m sparc SUNW,SPARCstation-5
//---------------------------------------------------------
//#########################################################
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]