[SOLVED] Compile error: No matching function / no known conversion

Good afternoon Arduino community! First time poster, pretty newb to the Arduino scene, and I’m at the point where I’m converting one of my sketches into a library & class (here I come organized code!).

Alas, like everyone, I have gotten myself narrowed down to this final snippet of problematic compiling:
ARDUINO IDE ERROR MESSAGE

Arduino: 1.8.10 (Windows 7), Board: "Arduino Due (Programming Port)"

E:\libraries\global_Conv\global_Conv.cpp: In member function 'void Conv::ParseJ1939(byte&, int&, long int&, byte*, byte, byte, byte)':

E:\libraries\global_Conv\global_Conv.cpp:74:71: error: no matching function for call to 'Conv::SerialPrint(long int*, byte&, byte&, byte&, int*, byte&)'

   SerialPrint(&lPGN, nDestAddr, nSrcAddr, nPriority, &nMsgLen, pMsg[0]);

                                                                       ^

E:\libraries\global_Conv\global_Conv.cpp:74:71: note: candidate is:

In file included from E:\libraries\global_Conv\global_Conv.cpp:6:0:

E:\libraries\global_Conv\global_Conv.h:28:8: note: void Conv::SerialPrint(long int&, byte, byte, byte, int&, byte*)

   void SerialPrint(long &lPGN, byte nDestAddr, byte nSrcAddr, byte nPriority, int &nMsgLen, byte pMsg[0]);

        ^

E:\libraries\global_Conv\global_Conv.h:28:8: note:   no known conversion for argument 1 from 'long int*' to 'long int&'

Multiple libraries were found for "ARD1939.h"
 Used: E:\
Multiple libraries were found for "global_Conv.h"
 Used: E:\
Multiple libraries were found for "SPI.h"
 Used: E:\
exit status 1
Error compiling for board Arduino Due (Programming Port).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

As can be seen from that error message, there’s something funky with the first int in the class (and if someone could confirm that when passing an array you do indeed just pass the first variable in the array? That’s got me a little on the fence, and there’s been a few changes to that in particular haha).

Relevant code as follows! :slight_smile:

global_Conv.h

#ifndef global_Conv_h
#define global_Conv_h

#include "Arduino.h"
#include "ARD1939.h"

//counter for timeouts
bool boolRun;
unsigned long nCount1;

ARD1939 j1939;

class Conv {
 public:
 Conv(byte ledPinGreen, byte ledPinEnable);
 void ParseJ1939(byte &nMsgId, int &nMsgLen, long &lPGN, byte pMsg[], byte nDestAddr, byte nSrcAddr, byte nPriority);
 void SerialPrint(long &lPGN, byte nDestAddr, byte nSrcAddr, byte nPriority, int &nMsgLen, byte pMsg[0]);
 byte _ledPinGreen;
 byte _ledPinEnable;
};

#endif

global_Conv.cpp

#include "global_Conv.h"

Conv::Conv(byte ledPinGreen, byte ledPinEnable){
 //Configure pins for output & input. 13 & 12
 pinMode(ledPinGreen, OUTPUT);
 pinMode(ledPinEnable, OUTPUT);
 const byte _ledPinGreen = ledPinGreen;
 const byte _ledPinEnable = ledPinEnable;
}

void Conv::ParseJ1939(byte &nMsgId, int &nMsgLen, long &lPGN, byte pMsg[0], byte nDestAddr, byte nSrcAddr, byte nPriority){
 // Check for a received message
 if(nMsgId == J1939_MSG_APP){
 SerialPrint(&lPGN, nDestAddr, nSrcAddr, nPriority, &nMsgLen, pMsg[0]);
 for(byte cIndex = 0; cIndex < nMsgLen; cIndex++){ //What kind of message was received
 if ((cIndex == 7) &&
 (lPGN == 12345) &&
 (pMsg[0] == 0x38) &&
 (pMsg[1] == 0x37) &&
 (pMsg[2] == 0x36) &&
 (pMsg[3] == 0x35) &&
 (pMsg[4] == 0x88) &&
 (pMsg[5] == 0x88) &&
 (pMsg[6] == 0x88) &&
 (pMsg[7] == 0x88)) {
 ECUSeen();
 }
 if ((cIndex == 0) &&
 (lPGN == 12345) &&
 (pMsg[0] == 0x1)){
 MotorEnabled();
 }
 if ((cIndex == 7) &&
 (lPGN == 12345) &&
 (boolRun == true)){
 pMsg[0] = (pMsg[0] * 0x0202020202ULL & 0x010884422010ULL) % 1023;
 pMsg[1] = (pMsg[1] * 0x0202020202ULL & 0x010884422010ULL) % 1023;
 short RPM = (pMsg[1]<<8) + pMsg[0];
 OutputVMotor(RPM);
 }
 }
 }
}

void Conv::SerialPrint(long &lPGN, byte nDestAddr, byte nSrcAddr, byte nPriority, int &nMsgLen, byte pMsg[0]){
 Serial.print("PGN:");
    Serial.print(lPGN, HEX);

    Serial.print(" DA:");
    Serial.print(nDestAddr);

    Serial.print(" SA:");
    Serial.print(nSrcAddr);

    Serial.print(" P:");
    Serial.print(nPriority);

    Serial.print(" Data:");
 for(byte cIndex = 0; cIndex < nMsgLen; cIndex++){
      Serial.print(pMsg[cIndex], HEX);
      Serial.print(" ");
 }
 Serial.print("\n\r");
}

I very much appreciate any insight that may be had :slight_smile: Arduino, and C++ in general, is quite new to me :slight_smile:

First your declaration doesn't make sense because your last argument is byte pMsg[0]:

void SerialPrint(long &lPGN, byte nDestAddr, byte nSrcAddr, byte nPriority, int &nMsgLen, byte pMsg[0]);

If you want an array then byte pMsg[] might be appropriate.

In the call to this function why are you specifiying the address of lPGN and nMsgLen? The function declaration has these arguments declared as references.

SerialPrint(&lPGN, nDestAddr, nSrcAddr, nPriority, &nMsgLen, pMsg[0]);

Definitely trying to pass the array haha. I think I'm removing the 0 from too many places when I do it, as previously I was getting this error:

Arduino: 1.8.10 (Windows 7), Board: "Arduino Due (Programming Port)"

E:\libraries\global_Conv\global_Conv.cpp: In member function 'void Conv::ParseJ1939(byte&, int&, long int&, byte*, byte, byte, byte)':

E:\libraries\global_Conv\global_Conv.cpp:74:69: error: expected primary-expression before ']' token

   SerialPrint(&lPGN, nDestAddr, nSrcAddr, nPriority, &nMsgLen, pMsg[]);

                                                                     ^

Multiple libraries were found for "global_Conv.h"
 Used: E:\
Multiple libraries were found for "SPI.h"
 Used: E:\
Multiple libraries were found for "ARD1939.h"
 Used: E:\
exit status 1
Error compiling for board Arduino Due (Programming Port).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I was attempting to pass lPGN and nMsgLen as references for efficiency / conserving space (my understanding is that a reference is two bytes; as this is coded on a Due, the int nMsgLen would be four bytes).

lPGN and nMsgLen are initialized in the arduino's main loop() routine, and my logic here is to pass them along to the Parse1939, which then can pass stuff off again as need be in response to the if statements, keeping to only two bytes for the reference at each level.

Your call should look just like this:

SerialPrint(lPGN, nDestAddr, nSrcAddr, nPriority, nMsgLen, pMsg);

ToddL1962:
First your declaration doesn't make sense because your last argument is byte pMsg[0]:

void SerialPrint(long &lPGN, byte nDestAddr, byte nSrcAddr, byte nPriority, int &nMsgLen, byte pMsg[0]);

Subscript for function parameter's array is fine. The compiler just ignores it.

arduino_new:
Your call should look just like this:

SerialPrint(lPGN, nDestAddr, nSrcAddr, nPriority, nMsgLen, pMsg);

To clarify your response for my understanding here, the call doesn't need the ampersands to denote them as references because the function Conv::SerialPrint is already looking for references as it is defined, and will find the references to any variables it is passed?

BMooney:
To clarify your response for my understanding here, the call doesn't need the ampersands to denote them as references because the function Conv::SerialPrint is already looking for references as it is defined, and will find the references to any variables it is passed?

Yes.

Huge thanks to both of you, I'm compiling away again without any red. :slight_smile:

Marked title as solved, but if anyone chimes in with additional information I will be sure to check back occasionally to read and learn :slight_smile: