Click here to Skip to main content
15,942,710 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Sorting a list with class for complex types Pin
earl10-Jul-06 11:14
earl10-Jul-06 11:14 
GeneralRe: Sorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 15:07
Harold_Wishes10-Jul-06 15:07 
GeneralRe: Sorting a list with class for complex types Pin
earl11-Jul-06 4:27
earl11-Jul-06 4:27 
AnswerRe: Sorting a list with class for complex types [modified] Pin
Stephen Hewitt10-Jul-06 14:45
Stephen Hewitt10-Jul-06 14:45 
GeneralRe: Sorting a list with class for complex types Pin
Harold_Wishes10-Jul-06 15:00
Harold_Wishes10-Jul-06 15:00 
GeneralRe: Sorting a list with class for complex types Pin
Stephen Hewitt10-Jul-06 15:05
Stephen Hewitt10-Jul-06 15:05 
GeneralRe: Sorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 22:38
Harold_Wishes10-Jul-06 22:38 
GeneralRe: Sorting a list with class for complex types Pin
Stephen Hewitt11-Jul-06 1:06
Stephen Hewitt11-Jul-06 1:06 
A friend function is really a global function, not a member function. This would be clearer if the declaration and the definition were separated as is shown below:
struct data
{
    int Number;
    string Length;
    string Sequence;
    string N_Terminal;
    string C_Terminal;
    friend bool operator<(const data &L, const data &R); // Declaration.
};
 
// Definition.
bool operator<(const data &L, const data &R)
{
    return L.number > R.number;   
}


In this example the function doesn't even need to be made a friend as it doesn't access any protected or private members. With this modification it looks like this:
struct data
{
    int Number;
    string Length;
    string Sequence;
    string N_Terminal;
    string C_Terminal;
};
 
bool operator<(const data &L, const data &R)
{
    return L.number > R.number;   
}


When the compiler sees a < and one or both of the parameters (the expressions to the left and right of the <) is a user defined type it looks for a user defined operator<. It chooses from all the candidates by matching the types in the expression it is compiling with the types of the operator.

Steve
QuestionRTI - related (Zac Howland) can help [modified] Pin
Jay0310-Jul-06 4:43
Jay0310-Jul-06 4:43 
AnswerRe: RTI - related (Zac Howland) can help Pin
Zac Howland10-Jul-06 5:01
Zac Howland10-Jul-06 5:01 
GeneralRe: RTI - related (Zac Howland) can help Pin
Jay0310-Jul-06 5:16
Jay0310-Jul-06 5:16 
GeneralRe: RTI - related (Zac Howland) can help Pin
Jay0310-Jul-06 6:33
Jay0310-Jul-06 6:33 
GeneralRe: RTI - related (Zac Howland) can help Pin
Zac Howland10-Jul-06 6:54
Zac Howland10-Jul-06 6:54 
GeneralRe: RTI - related (Zac Howland) can help Pin
Jun Du10-Jul-06 7:20
Jun Du10-Jul-06 7:20 
AnswerRe: RTI - related (Zac Howland) can help Pin
earl10-Jul-06 7:24
earl10-Jul-06 7:24 
QuestionDeleting desktop shortcut while not administrator [modified] Pin
User 317373010-Jul-06 4:04
User 317373010-Jul-06 4:04 
AnswerRe: Deleting desktop shortcut while not administrator Pin
User 317373021-Jul-06 4:51
User 317373021-Jul-06 4:51 
QuestionGetting the Parent Window Handle Pin
HakunaMatada10-Jul-06 3:53
HakunaMatada10-Jul-06 3:53 
AnswerRe: Getting the Parent Window Handle Pin
Sarath C10-Jul-06 4:15
Sarath C10-Jul-06 4:15 
GeneralRe: Getting the Parent Window Handle Pin
HakunaMatada10-Jul-06 17:20
HakunaMatada10-Jul-06 17:20 
AnswerRe: Getting the Parent Window Handle Pin
Abhi Lahare10-Jul-06 4:15
Abhi Lahare10-Jul-06 4:15 
AnswerRe: Getting the Parent Window Handle Pin
FarPointer10-Jul-06 4:18
FarPointer10-Jul-06 4:18 
AnswerRe: Getting the Parent Window Handle Pin
ThatsAlok10-Jul-06 19:20
ThatsAlok10-Jul-06 19:20 
Questionlist control Pin
jokefake10-Jul-06 3:49
jokefake10-Jul-06 3:49 
AnswerRe: list control Pin
Sarath C10-Jul-06 4:17
Sarath C10-Jul-06 4:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.