我有一个带有const_iterator的模板化类P,我试图创建所述迭代器的向量并迭代该向量:
std::vector<typename P<A, B>::const_iterator>::const_iterator it;
问题是当我尝试编译时我得到
error: expected ‘;’ before ‘it’
关于为什么会发生这种情况的任何想法?
答案 0 :(得分:2)
typename
之前需要std::vector<>
,因为P<A, B>
中至少有一个模板参数是从属类型:
typename std::vector<typename P<A, B>::const_iterator>::const_iterator it;
答案 1 :(得分:1)
const_iterator
的两种用法都取决于模板参数;所以两者都需要typename
。
typename std::vector<typename P<A, B>::const_iterator>::const_iterator it;
^^^^^^^^ ^^^^^^^^