C++ - 迭代器向量未编译的迭代器

C++ - iterator for a vector of iterators not compiling

本文关键字:迭代器 编译 向量 C++      更新时间:2023-10-16

我有一个模板化类P,它有一个const_iterator,我正在尝试制作所述迭代器的向量并遍历该向量:

std::vector<typename P<A, B>::const_iterator>::const_iterator it;

问题是当我尝试编译时,我得到

error: expected ‘;’ before ‘it’

关于为什么会发生这种情况的任何想法?

std::vector<>之前还需要一个typename,因为P<A, B>中至少有一个模板参数是依赖类型:

typename std::vector<typename P<A, B>::const_iterator>::const_iterator it;

const_iterator的两种用法都依赖于模板参数;所以两者都需要typename

typename std::vector<typename P<A, B>::const_iterator>::const_iterator it;
^^^^^^^^             ^^^^^^^^