11

我有这样的代码:

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

class IWantToBeFriendsWithMyStruct
{
    friend struct MyStruct; //what is the correct syntax here ?
};

赋予模板友谊的正确语法是什么?

4

2 回答 2

18
class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U>
    friend struct MyStruct;
};

在 VS2008 中工作,并允许 MyStruct 访问该类。

于 2008-10-15T19:23:12.940 回答
7

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

class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U> friend struct MyStruct; 
}
于 2008-10-15T19:28:24.347 回答