I have code like this:
template <typename T, typename U> struct MyStruct {
T aType;
U anotherType;
};
class IWantToBeFriendsWithMyStruct
{
friend struct MyStruct; //what is the correct syntax here ?
};
What is the correct syntax to give friendship to the template ?
class B{ template<class V> friend int j(); } template<class S> g(); template<class T> class A { friend int e(); friend int f(T); friend int g<T>(); template<class U> friend int h(); }; Function e() has a one-to-many relationship with class A . Function e() is a friend to all instantiations of class A .
A template friend declaration can name a member of a class template A, which can be either a member function or a member type (the type must use elaborated-type-specifier).
The entities of variable, function, struct, and class can have templates.
class IWantToBeFriendsWithMyStruct
{
template <typename T, typename U>
friend struct MyStruct;
};
Works in VS2008, and allows MyStruct to access the class.
According to this site, the correct syntax would be
class IWantToBeFriendsWithMyStruct
{
template <typename T, typename U> friend struct MyStruct;
}
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