No matching function call when compiling for Teensy 3.5 (but was fine for Atmega328P)

Status
Not open for further replies.

bms001

New member
I wrote a template class to handle basic matrix operations.

It compiled fine on Teensy 3.5 until I added an overloaded parenthesis function, after which I am getting the error:
Code:
Arduino: 1.8.5 (Windows 10), TD: 1.41, Board: "Teensy 3.5, Serial, 120 MHz, Faster, US English"

In file included from D:\Documents\Arduino\Custom libraries\test_m2\test_m2.ino:1:0:

C:\Program Files (x86)\Arduino\libraries\Matrix/Matrix.h: In instantiation of 'Matrix<T, ROWS_LEFT, COLS_RIGHT> operator*(const Matrix<T, NUM_ROWS, NUM_COLS>&, const Matrix<T, SHARED_DIMENSION, COLS_RIGHT>&) [with T = float; unsigned char ROWS_LEFT = 3u; unsigned char SHARED_DIMENSION = 3u; unsigned char COLS_RIGHT = 1u]':

D:\Documents\Arduino\Custom libraries\test_m2\test_m2.ino:7:13:   required from here

C:\Program Files (x86)\Arduino\libraries\Matrix/Matrix.h:263:25: error: no match for call to '(const Matrix<float, 3u, 3u>) (uint8_t&, uint8_t&)'

         accumulator += a(i, k) * b(k, j);

I did not get this error when compiling for Atmega328P and I don't really understanding why I'm getting it now when compiling for Teensy 3.5.
I am using the Arduino IDE and Teensyduino add-on.

Edit: from looking at the error message, it seems that the arguments are passed as reference but the function expects them by value. I did try changing the function to require the arguments by reference but this did not have any effect. But I'm fairly sure I haven't understood this problem correctly.

Any ideas?

Attached:
Matrix.h - the library in question
MatrixWORKING.h - a working version, before I added the overloaded parenthesis operator
Matrix.ino - a sketch that will produce the error (when compiling for Teensy 3.5)
compilation_errors.txt - the full error message
 

Attachments

  • Matrix.h
    8.9 KB · Views: 67
  • test_m2.ino
    117 bytes · Views: 61
  • compilation_errors.txt
    2.4 KB · Views: 78
  • MatrixWORKING.h
    7.4 KB · Views: 68
Ok, so I've realised my mistake.

This compiler error:
Code:
passing 'const Matrix<float, 3u, 1u>*' as 'this' argument discards qualifiers
was my main issue and was because I was passing a const reference to a class instance into a function, and then calling a non-const member function of that instance.

As a relatively inexperienced user of C++, this was confusing. I also guess the compiler for Teensy 3.5 and Atmega328P is different and/or is using different settings, so that my mistake was allowed when compiling for the atmega.

I added a const getter function to use instead of the general overloaded parenthesis operator that I was using as an accessor previously.

If anyone is interested, I've attached the fixed code plus a sketch showing how it can be used.
 

Attachments

  • Matrix.h
    9.2 KB · Views: 50
  • Matrix.ino
    3.2 KB · Views: 46
Status
Not open for further replies.
Back
Top