简体   繁体   English

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

[英]C++ - iterator for a vector of iterators not compiling

I have a templated class P that has a const_iterator and i'm trying to make a vector of said iterators and iterate through that vector: 我有一个具有const_iterator的模板化类P,我试图制作一个上述迭代器的向量,并通过该向量进行迭代:

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

problem is when i try to compile i get 问题是当我尝试编译时我得到了

error: expected ‘;’ before ‘it’

any ideas as to why this is happening? 有什么想法为什么会这样?

你需要一个typename之前std::vector<>以及因为在模板参数中的至少一个P<A, B>是一个依赖型:

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

Both uses of const_iterator depend on template parameters; const_iterator两种用法都取决于模板参数。 so both need typename . 所以都需要typename

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM