你如何将结构模板标记为朋友?

2021-12-13 00:00:00 class syntax templates c++ friend

我有这样的代码:

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 ?

推荐答案

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

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

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

相关文章