Solved

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

Posted on 2012-03-21
5
1,439 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 32

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now