befriending a template parameter

J

jrwats

Ultimately I want to know if there is a workaround or clever trick to
accomplish:
temlpate<class T>
class A
{
friend class T;
private:
//functions...
};

class B : class A<B>
{
};

But... what got me to this point was the following - so if you can
accomplish the below I'll be 90% satisfied:

The non-template pattern:

class NoInheritBaseEx
{
private:
friend class NoInheritBaseImpl;
NoInheritBaseEx(){ }
};

// No class can inherit from NoInheritBaseImpl... well they can, but
// they cannot be instantiated because of the private constructor.
class NoInheritBaseImpl :
virtual NoInheritBaseEx
{
};


I want to be able to do:

template<class T>
class NoInheritBaseEx
{
private:
friend class T;
NoInheritBaseEx(){}
};

class NoInheritBasImpl :
virtual NoInheritBaseEx<NoInheritBaseImpl>
{
};
 

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

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,897
Members
47,439
Latest member
shasuze

Latest Threads

Top