Click here to Skip to main content
15,891,513 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
I am trying to get ``sort(begin, end, compare)`` to work, where begin and end are iterators and compare is a boolean function. The Asset constructor is commented out because it generates an error.

I have tried to follow the example in Beginners guide to the std::sort() funct - C++ Articles[^]

This is the code:
C++
class RDA_Names {
   struct Asset {                                        //!< Aseet data
     long long int asset_No   = 0;                       //!< Converted Asset Tracking number
     string        asset_Name = "";                      //!< Normalized 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;

   bool compare(const Asset& x, const Asset& y);
   
   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
   sort(asset_Data.begin(), asset_Data.end(), compare); // case 2
   sort(asset_Data.begin(), asset_Data.end(), comp);    // case 3
}; // void post_process_names()


For each case, the other two cases are commented out. The format of the errors is Error number(repetition), Error text, lines within
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\
where the error was reported.

Case 1:
C2893 (5) Failed to specialize function template 
          \include\algorithm Lines 7361, 7419, 7423, 7434, 7447
C2672 (5) 'operator __surrogate_func': no matching overloaded function found 
          \include\xutility Line 1622


Case 2:
C2780 (1) 'void std::sort(const _RanIt,const _RanIt)': expects 2 arguments - 3 provided	
C2672 (1) 'sort': no matching overloaded function found
C3867 (1) 'RDA_Names::compare': non-standard syntax; use '&' to create a pointer to member


Case 3:
C2064 (5) term does not evaluate to a function taking 2 arguments 
          \include\xutility  Line  1622
          \include\algorithm Lines 7419, 7423, 7434, 7447

AnswerRe: <algorithm> sort keeps generating error messages. Pin
Greg Utas26-Mar-21 1:21
professionalGreg Utas26-Mar-21 1:21 
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 
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
Mircea 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
Mircea Neacsu14-Mar-21 10:36 
AnswerRe: Win32 Structures Pin
11917640 Member 17-Mar-21 3:01
11917640 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
11917640 Member 17-Mar-21 19:19 
QuestionZoom image on mouse position Pin
Gopi Nath12-Mar-21 0:20
Gopi 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
Gopi Nath14-Mar-21 20:34 
QuestionSelect TRACE functions based on both a variable and a #define? Pin
arnold_w11-Mar-21 5:31
arnold_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 

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.