C++模板参数/类歧义

发布于 2024-08-31 10:40:35 字数 362 浏览 1 评论 0原文

在使用不同版本的 g++ 进行测试时,出现以下问题

template<class bra>
struct Transform<bra, void> : kernel::Eri::Transform::bra {
        static const size_t ni = bra::A::size;

bra::A 被解释为 kernel::Eri::Transform::bra::A,而不是g++ 4.1.2 的模板参数。另一方面,g++ 4.3 是正确的。

根据标准,什么才是正确的行为?

同时,我稍微重构一下,让问题消失。

while testing with different version of g++, the following problem came up

template<class bra>
struct Transform<bra, void> : kernel::Eri::Transform::bra {
        static const size_t ni = bra::A::size;

bra::A is interpreted as kernel::Eri::Transform::bra::A, rather than template argument by g++ 4.1.2. on the other hand, g++ 4.3 gets it right.

what should be correct behavior according to standard?

Meanwhile, I refactor slightly to make problem go away.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的痛♀有谁懂 2024-09-07 10:40:35

在我看来 gcc 4.1.2 是正确的。 §14.6.1/7(ISO/IEC 14882,C++03)

在类模板的定义中或出现在模板定义之外的此类模板的成员的定义中,对于每个不依赖于模板参数的基类 (14.6.2),如果基类名称或基类成员名称与模板参数名称相同,基类名称或成员名称隐藏模板参数名称(3.3.7)。

Seems to me like gcc 4.1.2 was right. §14.6.1/7 (ISO/IEC 14882, C++03):

In the definition of a class template or in the definition of a member of such a template that appears outside of the template definition, for each base class which does not depend on a template-parameter (14.6.2), if the name of the base class or the name of a member of the base class is the same as the name of a template- parameter, the base class name or member name hides the template-parameter name (3.3.7).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文