By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,125 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,125 IT Pros & Developers. It's quick & easy.

Class templates and friend function templates

P: n/a
I have a class template like this:

template< typename t >
class c;

I'd also like to have an operator == for objects of types, which are
different specializations of c:

template< typename t1, typename t2 >
bool operator ==
(
s< t1 > const&
, s< t2 > const&
);

In order to implement this operator, I need it to be a friend of both
s< t1 > and s< t2 >. For the sake of safety, I'd like no other
specialization of c to have this operator as its friend. Is this
possible and, if so, how?

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Ian
BigMan wrote:
I have a class template like this:

template< typename t >
class c;

I'd also like to have an operator == for objects of types, which are
different specializations of c:

template< typename t1, typename t2 >
bool operator ==
(
s< t1 > const&
, s< t2 > const&
);

In order to implement this operator, I need it to be a friend of both
s< t1 > and s< t2 >. For the sake of safety, I'd like no other
specialization of c to have this operator as its friend. Is this
possible and, if so, how?

Why? What harm can a public operator == do?

Ian
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.