Thread: VC++ Map

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    34

    VC++ Map

    Hi guys,

    Can any of you tell me how to use map in C++ please?

    Thanks

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    I can tell you how to use google if you want.

    What do you want to know ?

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    34
    Sorry, I should post the code earlier. Here's what I'm trying to do:

    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];
    }
    I keep getting the error :"syntex error '[' ", any idea what's wrong?

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by GOBLIN-85 View Post
    Sorry, I should post the code earlier. Here's what I'm trying to do:

    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];
    }
    I keep getting the error :"syntex error '[' ", any idea what's wrong?
    Probably because v->[i] doesn't make any sense.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    just a thought
    Code:
    v->[i];
    should probably be
    Code:
    *v[i];
    im not positive, but that looks wierd to me

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    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.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding a Map to a program
    By Shogun32 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2009, 09:42 AM
  2. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  3. Creating a map engine.
    By suzakugaiden in forum Game Programming
    Replies: 11
    Last Post: 06-21-2005, 05:06 AM
  4. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM
  5. Searching STL Map Inside STL Map Object :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2002, 09:11 AM