模板参数为朋友 [英] Template parameter as a friend

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

问题描述

在C ++ 03中,以下是非法的,虽然有些编译器支持它。

In C++03 the following is illegal, although some compilers support it.

template <class T>
class X
{
    friend T;
};

这是否已在C ++ 11中合法化? (对不起,没有时间自己读草稿,只是希望有人知道这一点)

Has this been legalized in C++11? (Sorry, didn't have time to read the draft myself, just hoping someone knows this)

推荐答案

3在N3291中:

template <typename T> class R {
  friend T;
};

R<C> rc; // class C is a friend of R<C>
R<int> Ri; // OK: "friend int;" is ignored

因此在C ++ 11中是合法的。

So it is legal in C++11.

这篇关于模板参数为朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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