Click here to Skip to main content
15,896,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: EACCES when not running under VS debugger Pin
Richard MacCutchan12-Apr-21 1:52
mveRichard MacCutchan12-Apr-21 1:52 
GeneralRe: EACCES when not running under VS debugger Pin
ForNow12-Apr-21 2:02
ForNow12-Apr-21 2:02 
Questionuse of dependent type name must be prefixed Pin
_Flaviu1-Apr-21 7:02
_Flaviu1-Apr-21 7:02 
AnswerRe: use of dependent type name must be prefixed Pin
Greg Utas1-Apr-21 8:00
professionalGreg Utas1-Apr-21 8:00 
GeneralRe: use of dependent type name must be prefixed Pin
_Flaviu1-Apr-21 8:25
_Flaviu1-Apr-21 8:25 
GeneralRe: use of dependent type name must be prefixed Pin
Greg Utas1-Apr-21 10:50
professionalGreg Utas1-Apr-21 10:50 
GeneralRe: use of dependent type name must be prefixed Pin
_Flaviu1-Apr-21 19:34
_Flaviu1-Apr-21 19:34 
GeneralRe: use of dependent type name must be prefixed Pin
Greg Utas2-Apr-21 3:02
professionalGreg Utas2-Apr-21 3:02 
AnswerRe: use of dependent type name must be prefixed Pin
Richard MacCutchan2-Apr-21 0:51
mveRichard MacCutchan2-Apr-21 0:51 
QuestionTo print two index in a sentence Pin
Eugene Low31-Mar-21 21:08
Eugene Low31-Mar-21 21:08 
AnswerRe: To print two index in a sentence Pin
Richard MacCutchan31-Mar-21 21:16
mveRichard MacCutchan31-Mar-21 21:16 
GeneralRe: To print two index in a sentence Pin
Eugene Low31-Mar-21 22:04
Eugene Low31-Mar-21 22:04 
GeneralRe: To print two index in a sentence Pin
Richard MacCutchan31-Mar-21 23:49
mveRichard MacCutchan31-Mar-21 23:49 
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
Member 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
Brothers 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
aschwarz25-Mar-21 22:12 
AnswerRe: <algorithm> sort keeps generating error messages. Pin
Greg Utas26-Mar-21 1:21
professionalGreg 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:
C++
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
aschwarz26-Mar-21 6:48 
AnswerRe: <algorithm> sort keeps generating error messages. Pin
Mircea Neacsu26-Mar-21 2:40
Mircea Neacsu26-Mar-21 2:40 
GeneralRe: <algorithm> sort keeps generating error messages. Pin
aschwarz26-Mar-21 10:27
aschwarz26-Mar-21 10:27 
GeneralRe: <algorithm> sort keeps generating error messages. Pin
Mircea Neacsu26-Mar-21 12:22
Mircea Neacsu26-Mar-21 12:22 

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.