473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

sort() function for user defined type

When I'm trying to compile the below program on the GPP compiler, it is
giving me errors like
" no match for operator < ..."

Can anybody please help me figure out the error?
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef struct node
{
int i;
int j;
bool operator<(struct node& n1)
{
return (*this.i < n1.i);
}
}node;

int main(void)
{
node data[10];
sort(data,data+10);
return 0;
}

Nov 2 '06 #1
2 1336
alice wrote:
When I'm trying to compile the below program on the GPP compiler, it
is giving me errors like
" no match for operator < ..."
Take a habit not to use '...' in your posts unless absolutely necessary.
>
Can anybody please help me figure out the error?
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef struct node
Drop this C habit. Should just be

struct node
{
int i;
int j;
bool operator<(struct node& n1)
bool operator<(node const& n1) const
{
return (*this.i < n1.i);
}
}node;
And remove it here. Should just be

};
>
int main(void)
{
node data[10];
sort(data,data+10);
return 0;
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 2 '06 #2

Victor Bazarov wrote:

You missed one.
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef struct node

Drop this C habit. Should just be

struct node
{
int i;
int j;
bool operator<(struct node& n1)

bool operator<(node const& n1) const
{
return (*this.i < n1.i);
The above line should be:

return (i < n1.i);

or if you insist on keeping the "this" (Why?), then it should be:

return (this->i < n1.i);

Best regards,

Tom

Nov 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: maynard | last post by:
Is there a way to check if an object is an instance of a user-defined type or an integral type? I have a templated class that this would be very handy in (do _something_ if the template parameter...
2
by: Ronny Sigo | last post by:
Hello all, I am trying to write a prog that autamatically sends emails ... Here is what I have done so far In the module section I have put this: Public Function SendEmail(email As String,...
6
by: Earl Anderson | last post by:
In A97 on WinXP, I'm trying to use a KB function to provide the next sequential number in a custom counter (a table with two fields-- and ). When I run it, I get the "User-defined type not...
7
by: Siggy | last post by:
How can I trap this error -User-defined type not defined - in order to make custom error messages, when there is a missing reference, or missing dll/ocx file. Siggy
5
by: Macca | last post by:
Hi, My application receives data from multiple sources transferred over ethernet. This data is broken into packets of bytes before being transmitted over the network. My application has to...
1
by: zaeminkr | last post by:
I have a question about type conversion function for user defined type. I have two classes class DRect { private : double x0; double y0;
1
by: Mikael Vehkajärvi | last post by:
Hello I am running ASP.NET (C#) using Oracle (PL/SQL, provider ODP.NET 11.1.0.6.20) and I have a procedure which at the moment returns a table of records. The code below demonstrates this. ...
1
by: remya1000 | last post by:
i'm using VB.net 2003 application program. i'm trying to convert a VB6 program to VB.NET. The VB6 code i'm trying to convert is shown below. declared g_Share() array in module and trying to add...
6
by: p4willi | last post by:
I've defined two arrays in a Module called PubVars Public Type LinesRec CORRECT As Integer QUESTION As String PROC As Integer PAY As Integer End Type Public Lines_Array() As...
6
by: travjbad1 | last post by:
I am new to the forum and new to Access, so please be simple and descriptive if possible. I am having a problem with a button on a form that saves, opens a report in pdf, and emails the report to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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...

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.