Class templates and friend function templates

Discussion in 'C++' started by BigMan, Jul 23, 2005.

  1. BigMan

    BigMan Guest

    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?
     
    BigMan, Jul 23, 2005
    #1
    1. Advertising

  2. BigMan

    Ian Guest

    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
     
    Ian, Jul 23, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Vinokur
    Replies:
    1
    Views:
    379
    mlimber
    Jun 6, 2006
  2. recover
    Replies:
    2
    Views:
    857
    recover
    Jul 25, 2006
  3. ciccio
    Replies:
    4
    Views:
    488
    ciccio
    Jan 18, 2008
  4. Replies:
    2
    Views:
    698
    Triple-DES
    Feb 26, 2008
  5. Peter
    Replies:
    2
    Views:
    310
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page