How do you mark a struct template as friend?

2019-01-12 00:13发布

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 ?

2条回答
成全新的幸福
2楼-- · 2019-01-12 00:45
class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U>
    friend struct MyStruct;
};

Works in VS2008, and allows MyStruct to access the class.

查看更多
萌系小妹纸
3楼-- · 2019-01-12 00:55

According to this site, the correct syntax would be

class IWantToBeFriendsWithMyStruct
{
    template <typename T, typename U> friend struct MyStruct; 
}
查看更多
登录 后发表回答