为什么该标准禁止部分专业领域的朋友声明? [英] Why does the Standard prohibit friend declarations of partial specializations?

查看:60
本文介绍了为什么该标准禁止部分专业领域的朋友声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++标准禁止对部分专业化的朋友声明. (§14.5.3/8):

The C++ standard prohibits friend declarations of partial specializations. (§14.5.3/8):

朋友声明不应声明部分专业化. [示例:

Friend declarations shall not declare partial specializations. [Example:

template<class T> class A { };
class X {
    template <class T> friend class A<T*>;   //error
};

-最终示例]

--end example]

其他问题,例如这一个, 已收到援引此禁令的答案,但我想知道 基本原理.我没有看到它,也无法在我最喜欢的搜索引擎中找到它.一世 可以发现它可以追溯到C ++ 98标准,所以大概 基本原理是非常基本和明确的.有人可以向我解释吗?

Other questions, e.g. this one, have received answers that invoke this prohibition, but I would like to know the rationale. I don't see it and can't find it with my favourite search engine. I can find however that it goes right back to the C++98 standard, so presumably the rationale is quite basic and clear. Can someone explain it to me?

推荐答案

我没有引用,但我怀疑这是因为这会导致在朋友声明类的范围内声明部分专业化,而不是而不是创建一堆规则来强迫好友声明导致特定化在正确的范围内,而只是禁止它.

I don't have a reference but I suspect that this is because it would result in the partial specialization being declared in the scope of the friend-declaring class rather than the scope of the template in question, and rather than creating a bunch of rules to force the friend declaration to result in the specialization being in the correct scope, they simply prohibit it.

这篇关于为什么该标准禁止部分专业领域的朋友声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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