Click here to Skip to main content
15,613,470 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to typedef array of 4 char to be used in map template still getting compile errors Pin
CPallini15-Dec-22 3:01
mveCPallini15-Dec-22 3:01 
GeneralRe: how to typedef array of 4 char to be used in map template still getting compile errors Pin
ForNow15-Dec-22 3:12
ForNow15-Dec-22 3:12 
GeneralRe: how to typedef array of 4 char to be used in map template still getting compile errors Pin
CPallini15-Dec-22 3:22
mveCPallini15-Dec-22 3:22 
GeneralRe: how to typedef array of 4 char to be used in map template still getting compile errors Pin
ForNow15-Dec-22 3:33
ForNow15-Dec-22 3:33 
QuestionRe: how to typedef array of 4 char to be used in map template still getting compile errors Pin
CPallini15-Dec-22 3:40
mveCPallini15-Dec-22 3:40 
AnswerRe: how to typedef array of 4 char to be used in map template still getting compile errors Pin
ForNow15-Dec-22 3:51
ForNow15-Dec-22 3:51 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
ForNow15-Dec-22 12:47
ForNow15-Dec-22 12:47 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
CPallini15-Dec-22 20:46
mveCPallini15-Dec-22 20:46 
That compiles. However it is probably NOT what you want (both the key of the map and the < operator use the address of the c array).
Run
C++
ESDID e1, e2;
// init e1, e2 with the same content
e1.c[0] = e1.c[1] = e1.c[2] = e1.c[3] = 'A';
e2.c[0] = e2.c[1] = e2.c[2] = e2.c[3] = 'A';

cout << std::boolalpha;
cout << "(e1 < e2) " << (e1 < e2) << "\n";
cout << "(e2 < e1) " << (e2 < e1) << "\n";
and watch the resulting output. Can you spot the problem?


You can do something like this:
struct ESDID
{
  char c[4];
  // overload of the cast operator
  operator uint32_t () const { return  ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//...
  syminfo s1;
  map <uint32_t, syminfo> m;
  m.insert( pair<uint32_t, syminfo>(s1.symesdid, s1) );

Note the key of the map uses the content of the c array.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto

GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
ForNow16-Dec-22 2:40
ForNow16-Dec-22 2:40 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
CPallini16-Dec-22 3:00
mveCPallini16-Dec-22 3:00 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
Richard MacCutchan15-Dec-22 21:27
mveRichard MacCutchan15-Dec-22 21:27 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
ForNow16-Dec-22 2:41
ForNow16-Dec-22 2:41 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
CPallini16-Dec-22 2:53
mveCPallini16-Dec-22 2:53 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
ForNow16-Dec-22 3:06
ForNow16-Dec-22 3:06 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
CPallini16-Dec-22 3:19
mveCPallini16-Dec-22 3:19 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
ForNow16-Dec-22 3:37
ForNow16-Dec-22 3:37 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
CPallini16-Dec-22 4:38
mveCPallini16-Dec-22 4:38 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
ForNow16-Dec-22 5:11
ForNow16-Dec-22 5:11 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
Richard MacCutchan16-Dec-22 6:26
mveRichard MacCutchan16-Dec-22 6:26 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
CPallini16-Dec-22 6:59
mveCPallini16-Dec-22 6:59 
GeneralRe: how to typedef array of 4 char to be used in map template my solution CPallini hope you read this thank you Pin
ForNow16-Dec-22 7:57
ForNow16-Dec-22 7:57 
QuestionCcmdtarget() assertion and relaise failure Pin
Zouaoui Billel8-Dec-22 9:00
Zouaoui Billel8-Dec-22 9:00 
AnswerRe: Ccmdtarget() assertion and relaise failure Pin
Victor Nijegorodov8-Dec-22 9:43
Victor Nijegorodov8-Dec-22 9:43 
QuestionProper way to put a C++ object inside a struct initialization? Pin
arnold_w5-Dec-22 1:01
arnold_w5-Dec-22 1:01 
AnswerRe: Proper way to put a C++ object inside a struct initialization? Pin
CPallini5-Dec-22 1:15
mveCPallini5-Dec-22 1:15 

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.