I have a class with protected and/or private members that need to be accessed by
a close relative but template class. Normally one would make the second class
friend of the first, but when this second class is a template, how can I
accomplish it then?
//#
//# class A
//#
class A
{
public:
friend class B; //* This wont work, because class B is template
private:
void privateFunction();
};
//#
//# template class B
//#
template <class XType>
class B
{
public:
void myFunction( A *ptrA )
{ ptrA->privateFunction(); }
};
//#
//#
Any ideas would be greatly appreciated.
Wiljo.
> I have a class with protected and/or private members that need to be
> accessed by a close relative but template class. Normally one would
> make the second class friend of the first, but when this second class
> is a template, how can I accomplish it then?
Do you want all specializations of B to be friends of A, or just one
particular specialization?
> //#
> //# class A
> //#
> class A
> {
> public:
>
> friend class B; //* This wont work, because class B is template
>
> private:
> void privateFunction();
> };
> //#
> //# template class B
> //#
> template <class XType>
> class B
> {
> public:
> void myFunction( A *ptrA )
> { ptrA->privateFunction(); }
> };
> //#
> //#
What's the point in making B a template?
> Do you want all specializations of B to be friends of A, or just one
> particular specialization?
>
Yes, I want all specializations of B to be friend of A.
>
> What's the point in making B a template?
Well I oversimplified the example code a bit too much, and I didn't make sense
anymore. B needs to be template, because it handles several different object
types. The one thing they have in common is that they are all derived from class
A. A has private functionality, that I don't wan't to access directly from any
derived class, hence the private specifier. I DO wan't to access these private
functionality from the template class though. Hence my question.
I solved the problem by making a base class for the template class B. This base
class can be friend of A without any problem.
Thanks anyway.
Wiljo.
This is the wrong newsgroup for this topic.
Cf. my answer over in .cppbuilder.language