次の点を考慮してください。
template<int N>
class A
{
public:
A() : i(N) {}
template<int K>
void foo(A<K> other)
{
i = other.i; // <-- other.i is private
}
private:
int i;
};
int main()
{
A<1> a1;
A<2> a2;
a1.foo(a2);
return 0;
}
メンバーiとfooを共通の基本クラスに移動したり、フレンド クラス A<1>を追加するようなおかしなことをしたりせずに、「other.i」を表示する方法はありますか?
つまり、同じテンプレート クラスのテンプレートを友達にする方法はありますか?