0

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.
4
Contributors
8
Replies
9
Views
11 Years
Discussion Span
Last Post by winbatch
0

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<int, int, std::less<int>, std::allocator<std::pair<const int, int>>>::insert(int, int).
1 Error(s) detected.

0

Basically same error:

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

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.