assume that I have the following two template classes :
template <class _A>
class First
{
private:
int a;
};
template <class _B>
class Second
{
private:
int b;
};
how can I link them in many-to-many friendship. for example, adding a method in First that prints b of a parameter object of Second.
is my question clear?
This will enable every
First<T>
to access the internals of everySecond<U>
. Now, while this is the technical solution, you might want to consider whether a design with cyclic dependencies and opening up the internal to any instantiation of the other class is the best solution to your particular problem.BTW, if you only want to grant
First<int>
access toSecond<int>
(and notSecond<double>
) you can do that like so:In this second version you need the forward declaration of the
Second
template before befriending a particular instantiation, but this allows you to grant access to the internals of the class only to a particular instantiation.