How do I get an Iterator over a vector of objects from a Template?

Posted by nieldw on Stack Overflow See other posts from Stack Overflow or by nieldw
Published on 2010-03-19T12:09:14Z Indexed on 2010/03/19 12:11 UTC
Read the original article Hit count: 194

Filed under:
|
|
|
|

I'm busy implementing a Graph ADT in C++. I have templates for the Edges and the Vertices. At each Vertex I have a vector containing pointers to the Edges that are incident to it. Now I'm trying to get an iterator over those edges. These are the lines of code:

vector<Edge<edgeDecor, vertexDecor, dir>*> edges = this->incidentEdges();
vector<Edge<edgeDecor, vertexDecor, dir>*>::const_iterator i;
for (i = edges.begin(); i != edges.end(); ++i) {

However, the compiler won't accept the middle line. I'm pretty new to C++. Am I missing something? Why can't I declare an iterator over objects from the Edge template? The compiler isn't giving any useful feedback.

Much thanks niel

© Stack Overflow or respective owner

Related posts about c++

Related posts about iterator