Propagating #39;typedef#39; from based to derived class for #39;template#39;(将“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"从“模板"的基类传播到派生类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将“typedef"从“模板"的基类传播到派生类
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
