Imagine we have three template classes. The second class `B` should access private member of class `A` and class `C` should access private members of both classes `A` and `B`. I defined class `B` as `friend class` for class `A` and classes `B` and `C` as `friend` classes of class `A`.
template<int d, class T>
class B;
template<int d, class T>
class C;
template<int d>
class A
{
private:
int x;
...
public:
...
template <int, class T>
friendclass B;
template <int, class T>
friendclass C;
};
template<int d, class T>
class B
{
private:
A<d>* a;
public:
...
friendclass C<d, T>;
};
template<int d, class T>
class C
{
private:
B<d, T>* b;
public:
...
};
int main()
{
B<2, double> b;
C<2, double> c;
}
in linking process, class C can not access private member of class A (`A::x`), but class B can, i.e. class C can access `B::a` but not `A::x`. The error is `A::x is private within this context`
No I still have the problem. It was not the source of problem. I only thanks for correction of the question. It is a simple example of the problem I face and since the original code is quite large, I did not post it here.