template<class T,unsigned int I> class A;
template<unsigned int I>
class B{
// how 2 make A<T,I> a friend, with T as a template parameter?
You will either have to specify the type T in the friend declaration:
template<class T,unsigned int I> class A;
template<unsigned int I>
class B {
friend class A<int,I>; // T is int
};
Or you will have to provide another template parameter to B to use for
T:
template<class T,unsigned int I> class A;
template<class T,unsigned int I>
class B {
friend class A<T,I>;
}
AFAIK there is no way to say "declare all A<T,I> as friends of B<I>
for any T". C++03 [14.5.3/9] reads:
Friend declarations shall not declare partial specializations.
[Example:
template<class T> class A { };
class X {
template<class T> friend class A<T*>; // error};
--end example]
As a sanity check I tested the following:
template<class T,unsigned int I> A;
template<unsigned int I>
class B {
template<class T> friend class A<T,I>;
};
And it fails with the expected error:
"ComeauTest.c", line 11: error: a friend declaration may not declare a
partial
specialization
template <class T> friend class A<T,I>;
So I do not think it is possible.
Jason