Hi guys,
Can any of you tell me how to use map in C++ please?
Thanks
Printable View
Hi guys,
Can any of you tell me how to use map in C++ please?
Thanks
I can tell you how to use google if you want.
What do you want to know ?
Sorry, I should post the code earlier. Here's what I'm trying to do:
I keep getting the error :"syntex error '[' ", any idea what's wrong?Code:void GLMesh::convertToDiffCoord(Mesh *m)
{
//get the pointer to the list of pointers to all vertices
list<Vertex*>* v = m->get_vertices();
//initialize a map that will map each vertex pointer with an unique key
map<int, Vertex*> VMap;
//initialize iterator for the pointer list v
list<Vertex*>::iterator vi;
//iterate through the list and map each member in the list with a unique value
for (int i=0; i<v->size(); i++)
for(vi = v->begin(); vi != v->end(); vi++)
VMap[i] = v->[i];
}
just a thought
should probably beCode:v->[i];
im not positive, but that looks wierd to meCode:*v[i];
Your use of the map is fine.
Your for loops need work. You should only have one loop that increments i and vi together. Then, you probably want VMap[i] = *vi, since vi is an iterator to a list<Vertex*> and so *vi is a Vertex* which is what you're storing in a map.
If all you're going to do is map integers from 0 to some value in sequential order, wouldn't that make it a vector?