Solved error C2589: '(' : illegal token on right side of '::'
-
@SPlatten said in error C2589: '(' : illegal token on right side of '::':
, I've just kept it the same.
No, you don't.
You take the last element from the list withQList::takeLast()
. So your list will be 1 item shorter as begin. -
@KroMignon , the original code, which would compile:
groupList.back() = std::max(groupList.back(), sample);
The replacement:
double last = groupList.takeLast(); if ( sample > last ) last = sample; groupList.last() = last;
How is the new code different from the original, except now it compiles?
-
@SPlatten said in error C2589: '(' : illegal token on right side of '::':
How is the new code different from the original, except now it compiles?
You now overwrite the element before the last element: say you have 3 elements [A, B, C].
After takeLast() you have [A, B].
If you now execute groupList.last() = last; you will overwrite B. -
@jsulm , thank you, and the original just overrides the last item without removing it?
So if I just change it to:
double last = groupList.last(); if ( sample > last ) last = sample; groupList.last() = last;
-
@SPlatten said in error C2589: '(' : illegal token on right side of '::':
and the original just overrides the last item without removing it?
Yes.
With your code you can use append() instead of groupList.last() = last; to get same behaviour. -
@jsulm , but I'm not sure thats what the original was trying to do either. I think the original code would just update the last item.
-
@SPlatten said in error C2589: '(' : illegal token on right side of '::':
I think the original code would just update the last item
Yes, it updates the last element. Your code now removes the last element and updates the one before last (the new last element). So, to get same behaviour using takeLast() you have to append the element which takeLast REMOVES from the list:
[A, B, C] after takeLast() [A, B] after append() [A, B, C*] C* is the updated C
-
@jsulm , I think you missed one of my replies where I showed a replacement, changing the takeLast and replacing with just last.
-
@SPlatten The one using last() looks fine. Somehow overlooked it :-)
-
@SPlatten said in error C2589: '(' : illegal token on right side of '::':
thank you, and the original just overrides the last item without removing it?
Yes, that is the point:
QList::takeLast()
will return last element from QList and remove it from the listQList::last()
will only return a reference to last element from QList and not change list size.
-
@KroMignon, still no idea why the compiler was complaining about the original?
groupList.back() = std::max(groupList.back(), sample);
-
@SPlatten said in error C2589: '(' : illegal token on right side of '::':
still no idea why the compiler was complaining about the original?
I guess
sample
andgroupList.back()
do not have same type and std::max() template will not be able to match them.
Perhaps usingQList::constLast()
?// I prefere using Last() which is more clear as back() groupList.last() = std::max(groupList.constLast(), sample);
-
@KroMignon , but they do, sample is passed in as "const double sample". It could be ambiguous as the back method has two implementations one returns "const double &" and the other returns "double&".
-
@SPlatten
How about replacestd::max
withqMax
? -
@Bonnie Thanks, but I've moved on now, so much to do and so many errors and warnings to address.
-
@SPlatten said in error C2589: '(' : illegal token on right side of '::':
It could be ambiguous as the back method has two implementations one returns "const double &" and the other returns "double&".
Yes, depending on compiler this can be a problem. Again this is why I suggest you to change by using
QList::last()
andQList::constLast()
to avoid ambiguity:groupList.last() = std::max(groupList.constLast(), sample);
-
Your own win.h header suggests that you are compiling for Windows. There is a really old problem with including Windows.h as it defines a macro
max
. Most likely this is your problem. Even instd::max(...)
max
will be expanded which would explain your errors.The solution to this is that you define
NOMINMAX
either globally or before you include Windows.h (since it seems that you always include Windows.h through your own header win.h). -
@SimonSchroeder said in error C2589: '(' : illegal token on right side of '::':
here is a really old problem with including Windows.h as it defines a macro max
I didn't know this, thanks for this!
After a quit google search a found an interesting post on stackoverflow ==> https://stackoverflow.com/questions/13416418/define-nominmax-using-stdmin-maxI new thing a learned today :D