954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problems with multimap...

Why doesn't this compile? I am trying to use multimap and am unsuccessful.

#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
		multimap<string,long> test;
		string a="BLAH";
		long b=8;
		pair<string,long> c( a, b );
		test.insert( c );
		return 0;
}

CC Test.cpp -o Test
"Test.cpp", line 11: Error: Could not find a match for std::multimap<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, long, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char>>, long>>>::insert(std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char>>, long>).
1 Error(s) detected.
winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 
#include <string>
Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

Not the cause. I have the same problem with int:

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
int main()
{
		multimap<int,int> test;
		int a=6;
		int b=8;
		test.insert( a,b );
		return 0;
}

CC Test.cpp -o Test
"Test.cpp", line 11: Error: Could not find a match for std::multimap, std::allocator>>::insert(int, int).
1 Error(s) detected.

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 
test.insert( make_pair(a,b) );
Stoned_coder
Junior Poster
164 posts since Jul 2005
Reputation Points: 19
Solved Threads: 5
 

Basically same error:

CC Test.cpp -o Test
"Test.cpp", line 11: Error: Could not find a match for std::multimap, std::allocator>>::insert(std::pair).

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 
test.insert(pair<int,int>(a,b));


That works for me..?

-Fredric

Daishi
Junior Poster in Training
80 posts since Aug 2005
Reputation Points: 10
Solved Threads: 2
 

I think I'm coming to the conclusion that this is compiler specific...I'm using Sun Forte 6 (solaris)

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

its gotta be. If you include string in the first example, it should work. If you include functional in mine, it will work and also daishis example is valid too. You can get a different version of the stl and try that or maybe check for updates to your compiler because these codes mentioned are all standard compliant and should compile without fuss.

Stoned_coder
Junior Poster
164 posts since Jul 2005
Reputation Points: 19
Solved Threads: 5
 

apparently this is a known issue with the version of the compiler I'm using - I followed this link here and was succesful. (I tried the first suggestion of making the pair instead of pair . Haven't tried it with other datatypes yet.

http://forum.sun.com/thread.jspa?threadID=10941&messageID=30794#30794

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You