这是 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/