How do you mark a struct template as friend?

前端 未结 2 1547
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 15:27

I have code like this:

template  struct MyStruct {
    T aType;
    U anotherType;
};

class IWantToBeFriendsWithMyStruct
{
            


        
相关标签:
2条回答
  • 2020-12-03 15:37
    class IWantToBeFriendsWithMyStruct
    {
        template <typename T, typename U>
        friend struct MyStruct;
    };
    

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

    0 讨论(0)
  • 2020-12-03 15:48

    According to this site, the correct syntax would be

    class IWantToBeFriendsWithMyStruct
    {
        template <typename T, typename U> friend struct MyStruct; 
    }
    
    0 讨论(0)
提交回复
热议问题