传播'typedef'从基础到派生类为'模板' [英] Propagating 'typedef' from based to derived class for 'template'

查看:137
本文介绍了传播'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
};

为什么在BI收到一个错误,Vec_t无法识别,我需要明确写? p>

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:我发现重复的最后:这里是

UPD: I found duplicate finally: here it is.

这篇关于传播'typedef'从基础到派生类为'模板'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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