Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 
To complement what Greg was saying:
- case 3 fails because comp is a structure not a function returning a bool. Try changing it to:
C++
bool comp (const RDA_Names::Asset& lhs, const RDA_Names::Asset& rhs)
{
  return lhs.asset_No < rhs.asset_No;
}

You will have to also make Asset structure public.

As a case 4 you can try this:
C++
sort (asset_Data.begin (), asset_Data.end (), [](auto& l, auto& r)->bool {
  return l.asset_No < r.asset_No; });
where the comparison function is an anonymous lambda.

The next step is to look at how efficient your code will be. If you are sorting only 500 objects and you don't do it too often, it's probably OK. In general however your solution is highly inefficient. Every time sort has to exchange two elements it makes copies of the asset_Name string.

There are various ways to improve it:
- keep a unique_ptr pointer to string and provide a move constructor for the Asset structure.
- create an array of indexes in RDA_Names and sort it inseted of sorting the asset_Data array.
Mircea


modified 26-Mar-21 9:14am.

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 
GeneralRe: Select TRACE functions based on both a variable and a #define? Pin
arnold_w11-Mar-21 7:07
arnold_w11-Mar-21 7:07 
GeneralRe: Select TRACE functions based on both a variable and a #define? Pin
Richard MacCutchan11-Mar-21 23:11
mveRichard MacCutchan11-Mar-21 23:11 
GeneralRe: Select TRACE functions based on both a variable and a #define? Pin
arnold_w12-Mar-21 0:54
arnold_w12-Mar-21 0:54 

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.