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
If that snippet comes from a template, you have probably run into the problem of dependent names – use
typename:typenametells the compiler that you are referring to a type. Without it, dependent names are assumed to not be types or templates.For more details have a look at e.g. Comeaus template FAQ.