I wana know if we can make a partial specialized class as a friend class.
template< class A, class B >
class AB{};
class C;
template < class B >
class AB< C, B >{};
class D{
template< class E > friend class AB< D, E >;
}
How to achieve the above.
This is not allowed by the C++ Standard (§14.5.3/9):
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]
So basically, you can either make all instantiations of AB
friend of D
or only one particular instantiation. This IBM page describes the different relationships that can be achieved when it comes to friends and templates: "one-to-one", "one-to-many", "many-to-one" and "many-to-many" (but not "one-to-some" as you asked).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With