2014-04-07 194 views
0

我有了一个常量性模板化的P级,我试图让说迭代器的矢量并通过矢量迭代的向量:C++ - 迭代器迭代器不编译

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

问题当我试图编译我得到

error: expected ‘;’ before ‘it’ 

任何想法,为什么发生这种情况?

+1

你可以在P中粘贴'const_iterator'的typedef吗? – Sheljohn

+0

我不能=(但我保证它工作。 –

回答

2

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

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

const_iterator两种用法取决于模板参数;所以都需要typename

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