c++ - 模板 :Name resolution:Dependent types: -->can any one tell some more examples for this statement?

标签 c++ templates

这是 ISO C++ 标准 14.6.2.1 中的声明:依赖类型:

A type is dependent if it is
— a template parameter,#1
— a qualified-id with a nested-name-specifier which contains a class-name
   that names a dependent type or whose unqualified-id names a dependent type,#2
— a cv-qualified type where the cv-unqualified type is dependent, #3
— a compound type constructed from any dependent type,#4
— an array type constructed from any dependent type or whose size is specified
    by a constant expression that is value-dependent, #5
— a template-id in which either the template name is a template parameter
   or any of the template arguments is a dependent type or an expression 
   that is type-dependent or value-dependent.#6 

后两点我无法理解?

谁能给出这些陈述的例子(尤其是最后的#5,#6)?

最佳答案

1) 开始,如果类型是模板参数,则它是依赖的:

template <typename T, int N, template <typename> class My_Template>
struct X
{

5 — 由任何依赖类型构造的数组类型或其大小由依赖于值的常量表达式指定,

    T a[5];        // array of dependent type
    int b[N];      // value-dependent size

6 — 一个模板 ID,其中模板名称是模板参数
或者任何模板参数是依赖类型或表达式 即类型依赖或值依赖。

    My_Template<int> c;           // template parameter
    Some_Template<T> d;           // template argument is dependent
    Another_Template<sizeof c> e; // type-dependent expression
    Another_Template<N> f;        // value-dependent expression
};

关于c++ - 模板 :Name resolution:Dependent types: -->can any one tell some more examples for this statement?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3801167/

相关文章:

python - 将类型对象(类,而不是实例)从 python 传递到 c++

c++ - 使用什么作为缓冲区流的分隔符

c++ - GL_LINE_STIPPLE 在 ubuntu 中不起作用

c++ - 带有 const 引用的 std::remove_const

c++ - 为什么类内偏特化是良构的?

c++ - 执行特定功能取决于类型

c++ - Bin Packing 算法 - 实际变体

c++ - 用于 3D 数学的模板 Vector 类的代码重用问题

c++ - 函数特化 : Which is the declaration?

c++ - STL 关联容器 : erasing and getting back the (noncopyable) element