Click here to Skip to main content
14,927,528 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: To print two index in a sentence Pin
CPallini1-Apr-21 0:09
mveCPallini1-Apr-21 0:09 
Questionhelp me Pin
Member 1512893231-Mar-21 4:09
MemberMember 1512893231-Mar-21 4:09 
AnswerRe: help me Pin
Richard MacCutchan31-Mar-21 4:17
mveRichard MacCutchan31-Mar-21 4:17 
AnswerRe: help me Pin
CPallini31-Mar-21 19:54
mveCPallini31-Mar-21 19:54 
Questionc++ Pin
Brothers fun28-Mar-21 10:14
MemberBrothers fun28-Mar-21 10:14 
AnswerRe: c++ Pin
Dave Kreskowiak28-Mar-21 10:40
mveDave Kreskowiak28-Mar-21 10:40 
Question<algorithm> sort keeps generating error messages. Pin
aschwarz25-Mar-21 22:12
Memberaschwarz25-Mar-21 22:12 
AnswerRe: <algorithm> sort keeps generating error messages. Pin
Greg Utas26-Mar-21 1:21
mvaGreg Utas26-Mar-21 1:21 
Case 1 fails because there's no comparison function for sort. It might work if Asset defined operator<, but I'd have to check.

EDIT: If you define bool Asset::operator<(const Asset& that), then case 1 also compiles.

Case 2 fails because compare takes a this pointer. If a comparison function is going to be part of a class, it needs to be declared static.

Case 3, I'd have to investigate. I've used this struct technique, but only for a set I believe. It's likely that array doesn't use it.

Try making your compare function a free function (outside the class) or static and see what happens in case 2. In the meantime, I'll look at this further.

* * *

Fixing case 2 looks like the way to go. I compiled the following successfully, and the constructor didn't give me any problems:
class RDA_Names {
   struct Asset { 
     long long int asset_No   = 0; 
     string        asset_Name = ""; 
     Asset(long long int asset, string name): asset_No(asset), asset_Name(name) {}
   };

// struct {
//    bool compare(const Asset& lhs, const Asset& rhs) { return lhs.asset_No < rhs.asset_No; }
// } comp;

   static bool compare(const Asset& x, const Asset& y);

   void post_process_names();
   
   array<Asset, 500> asset_Data;

}; // class RDA_Names

bool RDA_Names::compare(const Asset& lhs, const Asset& rhs) {
   return (lhs.asset_No < rhs.asset_No);
}; // bool RDA_Names::compare(const Asset& x, const Asset& y)

void RDA_Names::post_process_names() {
// sort(asset_Data.begin(), asset_Data.end());           // case 1
   std::sort(asset_Data.begin(), asset_Data.end(), compare); // case 2
// sort(asset_Data.begin(), asset_Data.end(), comp);    // case 3
}; // void post_process_names()

Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.


modified 26-Mar-21 8:55am.

GeneralRe: <algorithm> sort keeps generating error messages. Pin
aschwarz26-Mar-21 6:48
Memberaschwarz26-Mar-21 6:48 
AnswerRe: <algorithm> sort keeps generating error messages. Pin
Mircea Neacsu26-Mar-21 2:40
mvaMircea Neacsu26-Mar-21 2:40 
GeneralRe: <algorithm> sort keeps generating error messages. Pin
aschwarz26-Mar-21 10:27
Memberaschwarz26-Mar-21 10:27 
GeneralRe: <algorithm> sort keeps generating error messages. Pin
Mircea Neacsu26-Mar-21 12:22
mvaMircea Neacsu26-Mar-21 12:22 
QuestionWin32 Structures Pin
Richard Andrew x6414-Mar-21 9:52
professionalRichard Andrew x6414-Mar-21 9:52 
AnswerRe: Win32 Structures Pin
Mircea Neacsu14-Mar-21 10:22
mvaMircea Neacsu14-Mar-21 10:22 
GeneralRe: Win32 Structures Pin
Richard Andrew x6414-Mar-21 10:32
professionalRichard Andrew x6414-Mar-21 10:32 
GeneralRe: Win32 Structures Pin
Mircea Neacsu14-Mar-21 10:36
mvaMircea Neacsu14-Mar-21 10:36 
AnswerRe: Win32 Structures Pin
11917640 Member 17-Mar-21 3:01
Member11917640 Member 17-Mar-21 3:01 
GeneralRe: Win32 Structures Pin
Richard Andrew x6417-Mar-21 9:20
professionalRichard Andrew x6417-Mar-21 9:20 
GeneralRe: Win32 Structures Pin
11917640 Member 17-Mar-21 19:19
Member11917640 Member 17-Mar-21 19:19 
QuestionZoom image on mouse position Pin
Gopi Nath12-Mar-21 0:20
MemberGopi Nath12-Mar-21 0:20 
AnswerRe: Zoom image on mouse position Pin
Richard MacCutchan12-Mar-21 1:28
mveRichard MacCutchan12-Mar-21 1:28 
GeneralRe: Zoom image on mouse position Pin
Gopi Nath14-Mar-21 20:34
MemberGopi Nath14-Mar-21 20:34 
QuestionSelect TRACE functions based on both a variable and a #define? Pin
arnold_w11-Mar-21 5:31
Memberarnold_w11-Mar-21 5:31 
AnswerRe: Select TRACE functions based on both a variable and a #define? Pin
Richard MacCutchan11-Mar-21 6:11
mveRichard MacCutchan11-Mar-21 6:11 
GeneralRe: Select TRACE functions based on both a variable and a #define? Pin
arnold_w11-Mar-21 7:07
Memberarnold_w11-Mar-21 7:07 

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.