Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

PumpkinPieman

Multimap Question

This topic is 5460 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know where I could find information on the basics of using Multimap. All I really need to know is Inserting, Deleting, Weither or not deleting will delete the object (If using pointers), returning a record from a key, and searching if a key exists (bool). If you have any other good STL tutorials and what not, feel free to post them. Thanks, Dave.

Share this post


Link to post
Share on other sites
Advertisement
I understand most of it now, but I'm still puzzled how one would go about searching for a key and getting a return of a returntype

std::multimap<int, int> newmap;
newmap.insert(std::pair<int, int>(100, 6));
newmap.insert(std::pair<int, int>(80, 7));
newmap.insert(std::pair<int, int>(120, 8));
newmap.insert(std::pair<int, int>(110, 9));

for (std::multimap<int, int>::iterator it = newmap.begin();
it != newmap.end();
++it)
std::cout << " [" << (*it).first << ", " << (*it).second << "]" << std::endl;


For searching, one wouldn't do a classical for loop with a multimap -- would they?

[edited by - PumpkinPieman on November 9, 2003 9:01:48 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by PumpkinPieman
How is multimap when dealing with pointers?


I''m not sure I understand your question.

Share this post


Link to post
Share on other sites
Well, I''m going to using it in two ways, one for handling pointers to an object. And the other to handle the objects themselves. But for some reason, when I try to work with pointers it''s giving me alot of errors.

Share this post


Link to post
Share on other sites
What compiler are you using, and what kind of errors are you getting? I''ve never had multimap give me any problems instantiating it with pointer types.

Share this post


Link to post
Share on other sites
As far as I know the standard .net one.

int newint = 20;

std::multimap<int, *int> newmap;
newmap.insert(std::pair<int, *int>(100, &newint));
newmap.insert(std::pair<int, *int>(80, &newint));
newmap.insert(std::pair<int, *int>(120, &newint));
newmap.insert(std::pair<int, *int>(110, &newint));

Maybe I'm doing something wrong.

c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(18) : error C2062: type 'int' unexpected
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(19) : error C2062: type 'int' unexpected
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(19) : error C2143: syntax error : missing ',' before ')'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(19) : error C2059: syntax error : ')'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(20) : error C2062: type 'int' unexpected
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(20) : error C2143: syntax error : missing ',' before ')'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(20) : error C2059: syntax error : ')'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(21) : error C2062: type 'int' unexpected
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(21) : error C2143: syntax error : missing ',' before ')'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(21) : error C2059: syntax error : ')'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(22) : error C2062: type 'int' unexpected
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(22) : error C2143: syntax error : missing ',' before ')'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(22) : error C2059: syntax error : ')'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(33) : error C2143: syntax error : missing ';' before '}'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(34) : error C2143: syntax error : missing ';' before '}'
c:\Documents and Settings\Dave\My Documents\Visual Studio Projects\Twilight\Main.cpp(34) : fatal error C1004: unexpected end of file found






[edited by - PumpkinPieman on November 9, 2003 9:22:23 PM]

Share this post


Link to post
Share on other sites
It's because you typed "* int" instead of "int *" when you declared your map.

edit: and your pairs.

[edited by - SiCrane on November 9, 2003 9:24:55 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!