I'm attempting to compile some c++ i2cdevlib code with gcc and I'm receiving the error:
/usr/share/arduino/libraries/i2cdevlib/Arduino/MPU9150/MPU9150_9Axis_MotionApps41.h: In member function 'uint8_t MPU9150::dmpInitialize()':
/usr/share/arduino/libraries/i2cdevlib/Arduino/MPU9150/MPU9150_9Axis_MotionApps41.h:605:56: error: no matching function for call to 'min(uint8_t&, int)'
getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
^
Why isn't there a min(uint8_t&, int)
defined? Isn't this a standard math function?
Am I correct in assuming I'm missing an include or namespace declaration somewhere, and shouldn't define this function myself?
The parameters that you pass to std::min
is different: one is uint8_t
and the other is int
.
The function type of std::min
is as follows:
template< class T >
const T& min( const T& a, const T& b );
You need tell the compiler what's the type parameter of std::min
.
So the solution is:
std::min<int>(fifoCount, 128);
Your error message says it all
error: no matching function for call to 'min(uint8_t&, int)'
The compiler fails to resolve to the correct specialization as the types of the parameter do not conform (match).
uint8_t
parameter fifoCount
to int
as in std::min(static_cast<int>(fifoCount), 128)
std::min<int>(fifoCount, 128)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With