C ++ 98标准在哪里指定本地声明的模板名称不依赖?

时间:2012-09-22 12:52:11

标签: c++ templates name-lookup dependent-name c++98

根据此页面: http://womble.decadent.org.uk/c++/template-faq.html#non-dependent “非依赖名称是那些被认为不依赖于模板参数的名称,加上模板本身的名称和在其中声明的名称(成员,朋友和局部变量)”

以下代码被认为有效(由LLVM / Comeau提供)这似乎得到了支持

template<typename T>
struct Template
{
    typedef int I;
    typedef Template::I Type; // 'Template' is NOT dependent
    typedef Template<T>::I Type2; // 'Template<T>' is NOT dependent
    Template<T>* m;
    void f()
    {
        m->f(); // 'm' is NOT dependent
    }
};

花了一些时间阅读C ++ 98标准后,我无法找到指定此行为的位置。我希望在'temp.nondep'下找到这个。

1 个答案:

答案 0 :(得分:1)

C ++ 98标准没有定义“非依赖”,“非依赖”或“非依赖”名称的确切含义(您可以在标准文本中找到所有三种形式)。

相反,它选择在14.6 [temp.res]及其子章节中定义哪些名称和类型依赖于模板参数。应用简单的逻辑......所有未被依赖的东西都是非依赖的。只读14.6.3 [temp.nondep]没有用。