我有这样的代码:

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

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

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

有帮助吗?

解决方案

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

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

其他提示

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

class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U> friend struct MyStruct; 
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top