Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Class templates and friend function templates

Reply
Thread Tools

Class templates and friend function templates

 
 
BigMan
Guest
Posts: n/a
 
      07-23-2005
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?

 
Reply With Quote
 
 
 
 
Ian
Guest
Posts: n/a
 
      07-23-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declare a Friend function which is a template member function of adifferent class getrakesh@gmail.com C++ 2 02-26-2008 11:32 AM
conflict between friend function and inherited class function ciccio C++ 4 01-18-2008 12:13 AM
how to Specializations of function Templates or Overloading Function templates with Templates ? recover C++ 2 07-25-2006 02:55 AM
Static function of some class as a friend of other class Alex Vinokur C++ 1 06-06-2006 12:16 PM
Correct syntax for class templates that declare friend functions Oplec C++ 5 10-28-2003 01:51 PM



Advertisments