作为好友的模板参数
在 C++03 中,以下内容是非法的,尽管某些编译器支持它。
template <class T>
class X
{
friend T;
};
这在 C++11 中合法化了吗? (抱歉,我自己没有时间阅读草稿,只是希望有人知道这一点)
In C++03 the following is illegal, although some compilers support it.
template <class T>
class X
{
friend T;
};
Has this been legalized in C++11? (Sorry, didn't have time to read the draft myself, just hoping someone knows this)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 N3291 中的第 §11.3, 3 节:
因此它在 C++11 中是合法的。
From section §11.3, 3 in N3291:
So it is legal in C++11.
是的,c++0x 允许模板参数成为朋友。
好吧,我碰巧记得之前在草稿中读过它,但找不到参考文献..无论如何@Praetorian 的答案钉住了它。
Yes c++0x allows template parameter to be friends.
Well, I happened to remember read it in the draft before but could not find the reference..anyways @Praetorian's answer nailed it.
在纯 C++ 中这是非法的,但有一个简单的解决方法
It is illegal in plain C++, but there is a simple workaround