Solved

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

Posted on 2012-03-21
5
1,517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 34

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

749 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