Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

719 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