Click here to Skip to main content
15,895,667 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
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 

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.