473,503 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error: no match for ‘operator<’ in ‘__x < __y’

1 New Member
In code there are two map.One store pair<key,Values> and other store <Values,key> where Values is class with 5 variable with data type string,int,string,int,int.but during inserting in the second map i am getting error g++ error: no match for ‘operator<’ in ‘__x < __y’ when trying to insert in map.
(Note Keys and Values in first map changes to Values,Key in second map)

How to solve it.
Expand|Select|Wrap|Line Numbers
  1.      class Values
  2.      {
  3.      private:
  4.         std::string C_addr;
  5.         int C_port;
  6.         std::string S_addr;
  7.         int S_port;
  8.         int C_ID;
  9.  
  10.      public:
  11.         Values(std::string,int,std::string,int,int);
  12.         void printValues();
  13.      };
  14.  
  15.  
  16.      Values :: Values(std::string Caddr,int Cport,std::string Saddr,int Sport,int Cid)
  17.      {
  18.         C_addr=Caddr;
  19.         C_port=Cport;
  20.         S_addr=Swaddr;
  21.         S_port=Sport;
  22.         C_ID=Cid;
  23.      }
  24.  
  25.      void Values::printValues()
  26.      {
  27.         cout << C_addr<<":" <<C_port<<":" << S_addr <<":" <<S_port << ":"<<C_ID  <<endl;
  28.      }
  29.  
  30.      map<int, Values> items;
  31.      map<Values,int> itemscopy;
  32.  
  33.      Values connection (inet_ntoa(Caddr.sin_addr),ntohs(Caddr.sin_port),inet_ntoa(Saddr.sin_addr),ntohs(Saddr.sin_port),CID);
  34.  
  35.      for(unsigned int key=0;key<=30000;    )
  36.      {
  37.         map<int,Values>::const_iterator itemsIterator=items.find(key);
  38.  
  39.         if(itemsIterator==items.end())
  40.         {
  41.            items.insert(pair<int, Values> (key, connection));
  42.            {
  43.               map<Values,int>::const_iterator itemsIterator1;
  44.               if(itemsIterator1==itemscopy.end())
  45.                  itemscopy.insert(pair<Values,int> (connection, key));
  46.            }
  47.            break;
  48.         }
  49.         else
  50.         {
  51.            cout<<"already exist";
  52.            key=key+1;
  53.         }
  54.      }
Mar 7 '14 #1
1 3882
Banfa
9,065 Recognized Expert Moderator Expert
It is doing that because the keys in a map are sorted using the < operator and your class Values has no implementation for this operation.

Add operator< to the class values.
Mar 7 '14 #2

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

Similar topics

7
9006
by: Ensoul Chee | last post by:
I used #include <iostream.h> int m; cout << "Hexadecimal == 0x" << hex << m << endl; to print value of m in hexadecimal mode. But I got the compile error like this couttest.cpp:20 `hex'...
5
1829
by: Steel | last post by:
Hi at all, please consider this : <ul> <li><a>No link</a></li> <li><a href="#">This is a link</a></li> <li><a>No link</a></li> <li><a href="#">This is a link</a></li> .......................
2
3238
by: ABC | last post by:
How can I fixed this error? Server Error in '/MAXXWeb' Application. -------------------------------------------------------------------------------- Parser Error Description: An error...
5
4473
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
1
8572
by: runistel | last post by:
i cant seem to find any fault, can anyone point out the error? void Itinerary::print() { list<Place>::iterator i; for(i = placelist.begin(); i != placelist.end(); i++) { cout...
3
3067
by: Yash | last post by:
Hi all, I found that while we are updating our application, the application is not known to tomcat, untill it is completed. So tomcat sends 503 page as resource not found. I want to know is...
1
10206
by: lovecreatesbea... | last post by:
In the following function `HardwareStatusDb()', If its arguments are declared as type of `string', I get: main.cpp:5: error: expected initializer before ‘int’. The error disappears when those...
5
5703
by: JerryBrit | last post by:
When compiling the below I get the following error: no match for 'operator<<' in 'log << std::endl' main.cpp Why can't I use std::endl in my class? #include <iostream> class Logger { ...
1
9781
by: Michael Fox | last post by:
The following code won't compile with g++, instead giving me the error: ----------------- prog2.cpp:36:33: error: declaration of ‘operator<<’ as non-function prog2.cpp:36:32: error: expected ‘;’...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.