Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-03-21
5
Medium Priority
?
1,624 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 35

Assisted Solution

by:sarabande
sarabande earned 1000 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

886 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