Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can a friend be a template function?

0 views
Skip to first unread message

Alex Vinokur

unread,
Jun 14, 1999, 3:00:00 AM6/14/99
to
In article <92912375...@iris.nyx.net>,
hru...@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.

Alex Vinokur

unread,
Jun 15, 1999, 3:00:00 AM6/15/99
to
In article <7k2hgb$kn6$1...@nnrp1.deja.com>,

Alex Vinokur <alexande...@telrad.co.il> wrote:
> In article <92912375...@iris.nyx.net>,
> hru...@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.
Sorry, it was an example with friend template classes.
> Alex
>
Here is an example with friend template functions.
Alex

P.S. See also the message titled
"Friend template function : Is the compiler right?"
comp.lang.c++
http://www.deja.com/[ST_rn=bg]/threadmsg_bg.xp?AN=489726420&fmt=text

//#########################################################
//------------------- C++ code : BEGIN -------------------

void funcAAA ();

template <typename T1> void funcBBB ();

template <typename T1, typename T2> void funcCCC ();

template <typename T1, typename T2, typename T3> void funcDDD ();


template <typename T1, typename T2, typename T3>
class FFF
{

friend void funcAAA ();

friend void funcBBB<T1> ();

friend void funcCCC<T1, T2> ();
friend void funcCCC<T1, T3> ();
friend void funcCCC<T2, T3> ();
friend void funcCCC<T3, T2> ();

friend void funcDDD<T1, T2, T3> ();
friend void funcDDD<T1, T3, T2> ();


private :
FFF (T1 t1) {}

public :
~FFF () {}
};

void funcAAA ()


{
FFF<int, char, float> (5);
}


template <typename T1>
void funcBBB ()


{
FFF<T1, double, float> (T1 ());
};


class XXX {};
int main ()
{
funcAAA ();

funcBBB<int> ();
funcBBB<char> ();
funcBBB<XXX> ();

0 new messages