Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Template friend can't be template parameter

Reply
Thread Tools

Template friend can't be template parameter

 
 
Gianni Mariani
Guest
Posts: n/a
 
      09-05-2003

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;
}

};

 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      09-05-2003
On 05 Sep 2003 01:45:20 GMT, Gianni Mariani <(E-Mail Removed)>
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
 
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
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
Using declaration inside first template parameter as default valuefor second template parameter. Stuart Redmann C++ 5 12-14-2007 08:42 AM
bound template parameter as argument to friend member functiondeclaration Justin Miller C++ 4 11-04-2004 02:34 PM
template parameter friend, it this valid ? Gianni Mariani C++ 5 05-20-2004 04:25 PM



Advertisments