I have a class template Obj1 with three template parameters
template < class A, class B, class C >
class Obj1
{
// some implementation
};
and the second class template Obj2 with two template parameters,
template < class A, class B >
class Obj2
{
// some implementation
};
so my problem is the following:
I want to make the class Obj1 to be the friend of class Obj2, with the first two template parameters with the same value, but I do not know the exact syntax how to write it, At first i tryed this way
template < class A, class B>
class Obj2
{
template< class C>
friend class Obj1<A,B,C>;
};
but it did not compile, so pleas help me if you can.
The answer to your question is here: https://stackoverflow.com/a/1458897/2436175 "You can only 'befriend' all instantiations of a class template or specific full specializations."
So, this is what is allowed:
template < class A, class B, class C >
class Obj1
{
// some implementation
};
template < class A, class B>
class Obj2
{
public:
template <class C, class D, class E> friend class Obj1; ///All instances
};
template < class A, class B>
class Obj3
{
public:
friend class Obj1<A,B,int>; ///One specific instantiation, possibly depending from your own templated parameters
friend class Obj1<A,B,A>; ///One specific instantiation, possibly depending from your own templated parameters
friend class Obj1<char,float,int>; ///One specific instantiation, possibly depending from your own templated parameters
};
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