将“typedef"从“模板"的基类传播到派生类

编程入门 行业动态 更新时间:2024-10-15 06:19:24
本文介绍了将“typedef"从“模板"的基类传播到派生类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试定义仅包含 typedef 的基类.

I'm trying to define base class, which contains typedef's only.

template<typename T> class A { public: typedef std::vector<T> Vec_t; }; template<typename T> class B : public A<T> { private: Vec_t v; // fails - Vec_t is not recognized };

为什么在 B 中我收到一个错误,指出 Vec_t 无法识别,我需要明确地编写它?

Why in B I receive an error that Vec_t is not recognized and I need to write it explicitly?

typename A<T>::Vec_t v;

推荐答案

我相信这个问题是重复的,但我现在找不到了.C++ 标准说你应该根据 14.6.2/3 完全限定名称:

I believe that this question is duplicate, but I cannot find it now. C++ Standard says that you should fully qualify name according to 14.6.2/3:

在类模板或类模板成员的定义中,如果类模板的基类依赖于模板参数,则在非限定名称查找期间不检查基类范围 在类模板或成员的定义点或在类模板或成员的实例化过程中.

In the definition of a class template or a member of a class template, if a base class of the class template depends on a template-parameter, the base class scope is not examined during unqualified name lookup either at the point of definition of the class template or member or during an instantiation of the class template or member.

UPD:我终于找到了重复:在这里.

更多推荐

将“typedef"从“模板"的基类传播到派生类

本文发布于:2023-08-04 09:19:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1295049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   派生类   typedef   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!