Solved

std::multimap<> C++ Solaris SunStudio 12 complilation error

Posted on 2012-03-21
5
1,502 Views
Last Modified: 2012-03-22
#include <iostream>
#include <map>
#include <string>

main(int argc, char* argv[])
{
    std::multimap<int, int> test;
    test.insert(std::pair<int,int>((int)1, (int)3));
}


CC mapTest.C
 

"mapTest.C", line 51: 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>) needed in main(int, char**).



Any help would help.


Thanks
0
Comment
Question by:sriram
  • 3
5 Comments
 
LVL 33

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 37751175
here is sample code from msdn

// multimap_insert.cpp
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   multimap <int, int>::iterator m1_pIter, m2_pIter;

   multimap <int, int> m1, m2;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );

   cout << "The original key values of m1 =";
   for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
      cout << " " << m1_pIter -> first;
   cout << "." << endl;

   cout << "The original mapped values of m1 =";
   for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
      cout << " " << m1_pIter -> second;
   cout << "." << endl;

   m1.insert ( Int_Pair ( 1, 10 ) );

   // The hint version of insert
   m1.insert( --m1.end( ), Int_Pair ( 4, 40 )  );

   cout << "After the insertions, the key values of m1 =";
   for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
      cout << " " << m1_pIter -> first;
   cout << "," << endl;

   cout << " and the mapped values of m1 =";
   for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
      cout << " " << m1_pIter -> second;
   cout << "." << endl;

   m2.insert ( Int_Pair ( 10, 100 ) );

   // The templatized version inserting a range
   m2.insert( ++m1.begin( ), --m1.end( ) );

   cout << "After the insertions, the key values of m2 =";
   for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
      cout << " " << m2_pIter -> first;
   cout << "," << endl;

   cout << " and the mapped values of m2 =";
   for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
      cout << " " << m2_pIter -> second;
   cout << "." << endl;
}

Open in new window


easier to handle than multimap<int, int> is std::map<int, std::vector<int> >.

std::map<int, std::vector<int> > test;
test[1].push_back(3);  
test[1].push_back(5);

Open in new window


Sara
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 250 total points
ID: 37751191
This seems to be a known issue with your compiler (or better yet, the STL implementation it's using).

In your compiler, for std::multimap<int, int>, the value type is std::pair<const int, int>, and not std::pair<int, int>.

So try using :

test.insert(std::multimap<int, int>::value_type((int)1, (int)3));

Open in new window


instead of :

test.insert(std::pair<int,int>((int)1, (int)3));

Open in new window

0
 

Author Comment

by:sriram
ID: 37753550
Thank You! I liked multimap<int, vector<>> too. If ::value_type doesn't work I will use vector as a workaround.

I tried using ::value_type(); worked for multimap<int,int> but got errors for class type multimap<long, FDProcess*>; where FDProcess is the class.



"/opt/SUNWspro/prod/include/CC/Cstd/rw/tree.cc", line 178: Error: Formal argument s1 of type std::string & in call to ltstr::operator()(std::string &, std::string &) const is being passed const unsigned long&.
"/opt/SUNWspro/prod/include/CC/Cstd/./map", line 489:     Where: While instantiating "__rwstd::__rb_tree<unsigned long, std::pair<const unsigned long, FDProcessor*>, __rwstd::__select1st<std::pair<const unsigned long, FDProcessor*>, unsigned long>, ltstr, std::allocator<std::pair<const unsigned long, FDProcessor*>>>::insert(const std::pair<const unsigned long, FDProcessor*>&)".
"/opt/SUNWspro/prod/include/CC/Cstd/./map", line 489:     Where: Instantiated from non-template code.
"/opt/SUNWspro/prod/include/CC/Cstd/rw/tree.cc", line 178: Error: Formal argument s2 of type std::string & in call to ltstr::operator()(std::string &, std::string &) const is being passed const unsigned long&.
"/opt/SUNWspro/prod/include/CC/Cstd/./map", line 489:     Where: While instantiating "__rwstd::__rb_tree<unsigned long, std::pair<const unsigned long, FDProcessor*>, __rwstd::__select1st<std::pair<const unsigned long, FDProcessor*>, unsigned long>, ltstr, std::allocator<std::pair<const unsigned long, FDProcessor*>>>::insert(const std::pair<const unsigned long, FDProcessor*>&)".
"/opt/SUNWspro/prod/include/CC/Cstd/./map", line 489:     Where: Instantiated from non-template code.
"/opt/SUNWspro/prod/include/CC/Cstd/rw/tree.cc", line 195: Error: Formal argument s1 of type std::string & in call to ltstr::operator()(std::string &, std::string &) const is being passed const unsigned long&.
"/opt/SUNWspro/prod/include/CC/Cstd/./map", line 489:     Where: While instantiating "__rwstd::__rb_tree<unsigned long, std::pair<const unsigned long, FDProcessor*>, __rwstd::__select1st<std::pair<const unsigned long, FDProcessor*>, unsigned long>, ltstr, std::allocator<std::pair<const unsigned long, FDProcessor*>>>::insert(const std::pair<const unsigned long, FDProcessor*>&)".
"/opt/SUNWspro/prod/include/CC/Cstd/./map", line 489:     Where: Instantiated from non-template code.
"/opt/SUNWspro/prod/include/CC/Cstd/rw/tree.cc", line 195: Error: Formal argument s2 of type std::string & in call to ltstr::operator()(std::string &, std::string &) const is being passed const unsigned long&.
"/opt/SUNWspro/prod/include/CC/Cstd/./map", line 489:     Where: While instantiating "__rwstd::__rb_tree<unsigned long, std::pair<const unsigned long, FDProcessor*>, __rwstd::__select1st<std::pair<const unsigned long, FDProcessor*>, unsigned long>, ltstr, std::allocator<std::pair<const unsigned long, FDProcessor*>>>::insert(const std::pair<const unsigned long, FDProcessor*>&)".
"/opt/SUNWspro/prod/include/CC/Cstd/./map", line 489:     Where: Instantiated from non-template code.
4 Error(s) detected.
0
 

Author Comment

by:sriram
ID: 37753624
Please ignore my previous comments. Yes, it worked for std::multimap<long, FDProcess*>; I found a declaration error.

I indeed liked both vector and value_type solutions. From code readable perspective vector solution is perfect but I liked value_type the most.

Thanks
0
 

Author Closing Comment

by:sriram
ID: 37753639
thanks for the quick solution
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question