Template friend can't be template parameter

G

Gianni Mariani

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

};
 
T

tom_usenet

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
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top