Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No matching function for call to 'min(uint8_t&, int)'

Tags:

c++

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?

like image 485
Cerin Avatar asked Jul 19 '16 04:07

Cerin


2 Answers

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);
like image 159
for_stack Avatar answered Nov 15 '22 18:11

for_stack


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).

  1. Either static upcast the uint8_t parameter fifoCount to int as in std::min(static_cast<int>(fifoCount), 128)
  2. Or, explicitly specify the type to specialize upon std::min<int>(fifoCount, 128)
like image 33
Abhijit Avatar answered Nov 15 '22 19:11

Abhijit