David
David

Reputation: 9965

How do you mark a struct template as friend?

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 ?

Upvotes: 11

Views: 7416

Answers (2)

Rob Walker
Rob Walker

Reputation: 47502

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

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

Upvotes: 18

Lev
Lev

Reputation: 6667

According to this site, the correct syntax would be

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

Upvotes: 7

Related Questions