error C2589: '(' : illegal token on right side of '::'
-
@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. -
@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
-
@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.
-
@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);
-
@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