你如何将结构模板标记为朋友? [英] How do you mark a struct template as friend?

查看:23
本文介绍了你如何将结构模板标记为朋友?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

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.

这篇关于你如何将结构模板标记为朋友?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆