Class templates and friend function templates

B

BigMan

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?
 
I

Ian

BigMan said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

friend templates 5
templates 10
templates?? 2
Using enable_if and function templates 2
Variadic templates std::tuple 2
Class templates and singleton container 3
Typename or class? 3
Template friend in templat class 8

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top