Error in comiling code for sensor

The error that I get once I compile my code is "E0040: expected an identifier" on this line of code where it says "max".

std::size_t scale = std::max({ size_t(1u), data->width / m_widthPerStream, data->height / MAX_HEIGHT });

This line of code is part of a sample code for a sensor and I can't figure out how to correct this error.
Last edited on
max is in <algorithm> and some embedded setups do not have all the language tools. Verify you included it and that it is supported, and if those are good, try max of 3 constants to see if its a variable issue.
It also gives a warning that there are too many arguments so could that be contributing to the issue?
std::max compares two values, so that is two parameters that can be compared.

There is a third parameter allowed for a binary function that over-rides the default < comparison.

C++11 and later added two additional overloads that allow for passing an initializer list, and an initializer list with a binary function.

You provided 3 values to compare, that doesn't match any of the 4 versions of std::max.

http://www.cplusplus.com/reference/algorithm/max/
it looks like he has a match for
max({item, item, item}) format? which is list without comparison?
is it a type problem, the first is int and the second double?
Last edited on
The error that I get once I compile my code is "E0040: expected an identifier" on this line

Compilers often provide a column number too, which might help identifying the issue.
Otherwise you can try to split your instruction into several lines, to see if the compiler points out another one, like for example:
1
2
3
4
5
std::size_t scale = std::max (
    { size_t(1u),
      data->width / m_widthPerStream,
      data->height / MAX_HEIGHT }
);


expected an identifier

Maybe the compiler refuses to deal with a temporary (size_t(1u)) or you cannot access m_widthPerStream, which looks like a member variable, without a fully qualified identifier, or… I don’t know :)

Edit: that’s just a casting, I didn’t realize it - it shouldn’t be a problem.

Last edited on
Topic archived. No new replies allowed.