如何将结构模板标记为朋友?

Dav*_*vid 11 c++ syntax templates class friend

我有这样的代码:

template <typename T, typename U> struct MyStruct {
    T aType;
    U anotherType;
};

class IWantToBeFriendsWithMyStruct
{
    friend struct MyStruct; //what is the correct syntax here ?
};
Run Code Online (Sandbox Code Playgroud)

为模板提供友谊的正确语法是什么?

Rob*_*ker 18

class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U>
    friend struct MyStruct;
};
Run Code Online (Sandbox Code Playgroud)

适用于VS2008,允许MyStruct访问该类.


Lev*_*Lev 7

根据这个网站,正确的语法将是

class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U> friend struct MyStruct; 
}
Run Code Online (Sandbox Code Playgroud)