隐藏成员模板的模板参数 [英] hiding of template parameter of member template

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

问题描述

来自 temp.local :

在出现在外部的类模板的成员的定义中 类模板定义的名称,类成员的名称 template隐藏任何封闭类的template-parameter的名称 模板(,但不是成员的模板参数,如果成员是 类或函数模板). [示例:

In the definition of a member of a class template that appears outside of the class template definition, the name of a member of the class template hides the name of a template-parameter of any enclosing class templates (but not a template-parameter of the member if the member is a class or function template). [ Example:

template<class T> struct A {
  struct B { /* ... */ };
  typedef void C;
  void f();
  template<class U> void g(U);
};

template<class B> void A<B>::f() {
  B b;              // A's B, not the template parameter
}

template<class B> template<class C> void A<B>::g(C) {
  B b;              // A's B, not the template parameter
  C c;              // the template parameter C, not A's C
}

—结束示例]

问题在于,我尝试过的每个编译器(g ++,vc,icc,clang)都将A<B>::g(C)中的C视为A的成员名称,而没有编译该示例.

the problem is that, each compiler, that i have tried ( g++, vc, icc, clang ), treats C in A<B>::g(C) as A's member name and doesn't compile that example.

这是一个常见的错误吗??

Is this a common bug.?

推荐答案

尽管您提供的链接似乎只是草稿,并明确声明它不是任何标准的一部分(

While the link you gave appears to be a draft and explicitly states it is not a part of any standard (http://eel.is/c++draft/), this particular clause in the draft appears to be identical to ISO C++ 14.6.1, paragraph 7.

因此,它的确似乎是常见的编译器错误,还是与其他子句冲突并丢失的子句.我确认该示例无法在MacOS Clang v802.0.42上编译.既然您说所有主要的编译器都在这里发出错误,我会怀疑由于与其他某些子句冲突而导致该子句的实现不合理.

So it does indeed seem to be either a common compiler bug or a clause that conflicts with and lost out to other clauses. I verified the example doesn't compile on MacOS Clang v802.0.42). Since you say all the major compilers emit errors here, I would suspect this clause is not reasonable to implement due to conflicts with some other clause(s).

我也在标准社区中找到了一个讨论这里与此主题相关. 在这里向我建议,该规则是有争议的,甚至可以更改.

I also found a discussion within the standards community here related to this topic. The depth with which it gets discussed here suggests to me that this rule is contentious and may even be changed.

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

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