By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,035 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,035 IT Pros & Developers. It's quick & easy.

Multiset with custom < operator - problem with iterators

P: 5
Hi everyone!

I have a following problem:

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<set>
  3.  
  4. using namespace std;
  5.  
  6. struct punkt
  7. {
  8.        int x;
  9.        int y;
  10.  
  11. };
  12.  
  13. struct porownaj_x {
  14.   bool operator() (const punkt& lhs, const punkt& rhs) const
  15.   {return lhs.x<rhs.x;}
  16. };
  17.  
  18. struct porownaj_y {
  19.   bool operator() (const punkt& lhs, const punkt& rhs) const
  20.   {return lhs.y<rhs.y;}
  21. };
  22.  
  23. int main()
  24. {
  25.  
  26.  
  27.     int z;
  28.     cin >> z;
  29.  
  30.     int a,b;
  31.     punkt zabytki[z];
  32.     for (int i=0; i<z; i++)
  33.     {
  34.     cin >> a >> b;
  35.     //tab[a][b]=1;
  36.     zabytki[i].x=a; 
  37.     zabytki[i].y=b;
  38.     }
  39.  
  40.  
  41.     multiset<punkt,porownaj_x> sx;
  42.     multiset<punkt,porownaj_y> sy;
  43.  
  44.     for (int i=0; i<z; i++)
  45.     { sx.insert(zabytki[i]);
  46.       sy.insert(zabytki[i]);}
  47.  
  48.    multiset<punkt, porownaj_x>::iterator itt;
  49.  
  50. int ub = 10;
  51. for (itt=sx.upper_bound(ub); itt!=sx.end(); itt++)
  52.     cout << " " << (*itt).x << " " << (*itt).y;
  53. cin.get();
  54. cin.get();
  55. return 0;
  56. }
  57.  
  58.  
  59.  

Compiler returns an error: 51 no matching function for call to `std::multiset<punkt, porownaj_x, std::allocator<punkt> >::upper_bound(int&)'

Multisets are working perfectly fine but upper_bound and lower_bound iterators aren't:( What is wrong in the code?
Nov 13 '08 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
Your multiset has punkt as the key.

Expand|Select|Wrap|Line Numbers
  1. multiset<punkt,porownaj_x> sx; 
  2.  
That means your iterator needs a punkt as a key. However, you are using ub which is an int. A punkt and an int are different types.Hence the compiler error.
Nov 13 '08 #2

boxfish
Expert 100+
P: 469
I think it's because you're passing an int to the upper_bound function. You have to give it an object of type punkt, its key type. I don't actually know what a multiset is; I just looked it up here.
Nov 13 '08 #3

P: 5
Your multiset has punkt as the key.

Expand|Select|Wrap|Line Numbers
  1. multiset<punkt,porownaj_x> sx; 
  2.  
That means your iterator needs a punkt as a key. However, you are using ub which is an int. A punkt and an int are different types.Hence the compiler error.

Thank you very very much for the quick reply!!! :)
Nov 13 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.