error C2589: '(' : illegal token on right side of '::'
-
@sierdzio , thanks , to me the logic just doesn't look right I have it compiling now, somehow its assigning a value to a const double reference.
The error has now changed, now I'm getting:
ocidl.h(45) : error C2146: syntax error : missing ';' before identifier
-
Is
sample
also adouble
? Perhapsstd::max
gets confused. -
@sierdzio , also just tried your example and it won't allow it:
const double existing = groupList.takeLast(); groupList.append(std::max(existing, sample));
The last line has exclamantion mark on it , the errors are:
error: C2589: '(' : illegal token on right side of '::' error: C2143: syntax error : missing ')' before '::' error: C2661: 'QList<double>::append' : no overloaded function takes 0 arguments error: C2059: syntax error : ')'
All of those on that line. Having just looked at the details on QList, I can see that the const version of back is an overloaded version, there is also an identical version without const.
In the end, this works:double last = groupList.takeLast(); if ( sample > last ) last = sample; groupList.last() = last;
-
@SPlatten said in error C2589: '(' : illegal token on right side of '::':
double last = groupList.takeLast();
if ( sample > last )
last = sample;
groupList.last() = last;I am not sure this is the same as
groupList.back() = std::max(groupList.back(), sample);
I think your should change to
double last = groupList.takeLast(); if ( sample > last ) last = sample; groupList.insert(last);
or
groupList.insert(std::max(groupList.takeLast(), double(sample)));
-
@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. -
@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);