Template friend can't be template parameter

Discussion in 'C++' started by Gianni Mariani, Sep 5, 2003.

  1. Does anyone know the wisdom behind this ?

    I want to make a template whose parameter needs to be a friend.

    What's the right(TM) way to do this ?

    template <typename T, typename TF>
    class Boo
    {
    friend class TF; // error: using template type
    // parameter `TF' after `class'

    friend TF; // error: template parameters cannot be friends

    template <typename TF2>
    class Obfuscator
    {
    public:

    typedef TF2 ObfusType;
    };

    // the following seems to work for GCC but not MSVC
    friend class Obfuscator<TF>::ObfusType;

    public:

    T value;
    };


    class Tester
    {
    public:

    Tester()
    {
    Boo< int, Tester > x;

    x.value = 1;
    }

    };
     
    Gianni Mariani, Sep 5, 2003
    #1
    1. Advertising

  2. Gianni Mariani

    tom_usenet Guest

    On 05 Sep 2003 01:45:20 GMT, Gianni Mariani <>
    wrote:

    >
    >Does anyone know the wisdom behind this ?
    >
    >I want to make a template whose parameter needs to be a friend.
    >
    >What's the right(TM) way to do this ?


    There isn't a right way - it is forbidden by 11.4/2 which says that an
    elaborated-type-specifier shall be used in a friend declaration for a
    class.

    For a detailed answer,
    http://makeashorterlink.com/?F24766EC5

    Tom
     
    tom_usenet, Sep 5, 2003
    #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. Gianni Mariani
    Replies:
    5
    Views:
    381
    Gianni Mariani
    May 20, 2004
  2. Justin Miller
    Replies:
    4
    Views:
    481
    Justin Miller
    Nov 4, 2004
  3. =?gb2312?B?wfXquw==?=
    Replies:
    10
    Views:
    710
    Victor Bazarov
    Aug 1, 2007
  4. A L
    Replies:
    1
    Views:
    527
    Alf P. Steinbach /Usenet
    Aug 25, 2010
  5. Peter
    Replies:
    2
    Views:
    295
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page