Function Declaration Error

I am creating an arduino library, composed of a .cpp file and a header file

Header:

void getCommand(byte *command);

cpp:

void RemoteC::getCommand(byte *command)
{
      //Function Defenition
}

Error:

\arduino-0019\libraries\RemoteC\RemotC.cpp:10: error: prototype for 'void RemoteC::getCommand(byte**)' does not match any in class 'RemoteC'
\arduino-0019\libraries\RemoteC\/RemoteC.h:12: error: candidate is: void RemoteC::getCommand(byte*)

Can anyone point out the problem?
Thank you :slight_smile: :slight_smile:

Your header needs a class definition, of which your function is declared as a public method.

I think we need to see more of your code. It appears from the error message that the code snippet from the .cpp file is not what is actually in the .cpp file.

The error message says that you are defining a function that takes an array of pointers, while the function is declared to take a single pointer.

Perhaps, though, it is the sketch that is calling the function that is in error. How are you calling the function?

This is the calss header(part of it):
#ifndef RemoteC_h
#define RemoteC_h

#include "WProgram.h"

class RemoteC
{
      public:
            RemoteC();
            void execute(int command, int port, int value);
            void getCommand(byte *command);
            ..
            ..
            ..
      private:
            byte _command[2];
            byte _port[2];
            ..
            ..
      };
#endif

I am not calling the function yet. I am constructing the class right now.
Thank you.

Just a guess...

\arduino-0019\libraries\RemoteC\RemotC.cpp:10: error: prototype for 'void RemoteC::getCommand(byte**)' does not match any in class 'RemoteC'
\arduino-0019\libraries\RemoteC\/RemoteC.h:12: error: candidate is: void RemoteC::getCommand(byte*)

RemotC.cpp and RemoteC.h???

Edit: Nevermind, having problems replicating the issue even with different filenames.

I give up already. :smiley:

RemoteC.h

#ifndef RemoteC_h
#define RemoteC_h

#include "WProgram.h"

class RemoteC
{
  public:
    void getCommand(byte *command);
};

#endif

RemotC.cpp

#include "RemoteC.h"

void RemoteC::getCommand(byte *command)
{
}

Works absolutely fine for me.

I suggest posting your complete RemotC.app code.

Eight....
THANK YOU! :smiley:

To late to party..
Still having the error..

\arduino-0019\libraries\RemoteC\RemoteC.cpp:10: error: prototype for 'void RemoteC::getCommand(byte**)' does not match any in class 'RemoteC'
\arduino-0019\libraries\RemoteC\/RemoteC.h:12: error: candidate is: void RemoteC::getCommand(byte*)

Lol. If I helped, I don't know how. :wink:

I think you for you help :slight_smile:

void RemoteC::getCommand(byte *command[])
{
      _command[] = {&command[0] , &command[1]};
      _port[] = {&command[2] , &command[3]};
      _value[] = {&command[4] , &command[5] , &command[6]};
      
      command = atoi(_command);
      port = atoi(_port);
      value  = atoi(_value);
      execute(command,port,value);
}

:smiley:

Ah, ok. In your function there you have overloaded getCommand() with different parameters.

Instead of passing in a pointer to a byte, you are asking for a pointer to an array of pointers to byte.

byte *command
vs
byte *command[]

So in RemoteC.h, just change it to
public: void getCommand(byte *command[]);

Although...

I'm going to guess you want to call the function with something like

byte myCommand[] = {0,1,2,3,4};
myRemoteC.getCommand(myCommand);

So:

RemoteC.h
void getCommand(byte command[]);

RemoteC.cpp
void RemoteC::getCommand(byte command[])
{
}

Might work better, and just avoid using pointers altogether. :smiley:

well, now there are some new errors:

\arduino-0019\libraries\RemoteC\RemoteC.cpp: In member function 'void RemoteC::getCommand(byte*)':
\arduino-0019\libraries\RemoteC\RemoteC.cpp:12: error: expected primary-expression before ']' token
\arduino-0019\libraries\RemoteC\RemoteC.cpp:12: error: expected primary-expression before '{' token
\arduino-0019\libraries\RemoteC\RemoteC.cpp:12: error: expected `;' before '{' token
\arduino-0019\libraries\RemoteC\RemoteC.cpp:13: error: expected primary-expression before ']' token
\arduino-0019\libraries\RemoteC\RemoteC.cpp:13: error: expected primary-expression before '{' token
\arduino-0019\libraries\RemoteC\RemoteC.cpp:13: error: expected `;' before '{' token
\arduino-0019\libraries\RemoteC\RemoteC.cpp:14: error: expected primary-expression before ']' token
\arduino-0019\libraries\RemoteC\RemoteC.cpp:14: error: expected primary-expression before '{' token
\arduino-0019\libraries\RemoteC\RemoteC.cpp:14: error: expected `;' before '{' token
line12:      _command[] = {command[0] , command[1]};
      _port[] = {command[2] , command[3]};
      _value[] = {command[4] , command[5] , command[6]};

And how can I convert byte array to integer?
Thank you.

Try

void RemoteC::getCommand(byte command[])
{
      _command[] = {command[0] , command[1]};
      _port[] = {command[2] , command[3]};
      _value[] = {command[4] , command[5] , command[6]};

      command = atoi(_command);
      port = atoi(_port);
      value  = atoi(_value);
      execute(command,port,value);
}

No & signs since we're not explicitly using pointers.

Missed the second half of your question there.

You want command to be a string or integer, made up of the two bytes in command[0] and command[1]?

I have no way of checking this here; but
if
command[0] = 08h
command[1] = 10h
and you wanted the final command to be 0810h then you could use bit shifting.

Something like this MIGHT work.

void RemoteC::getCommand(byte command[])
{
int iCommand = ((int)command[0] << 8) || command[1];
int iPort = ((int)command[2] << 8) || command[3];
int iValue  = (((int)command[4] << 16) || ((int)command[5] << 8)) || command[6];
execute(iCommand,iPort,iValue);
}

Yes sir,
the command is the [0] and [1], the port is [2] and [3] and the value is [4][5][6].
example :
byte myCommand[] = {0,8,2,8,4,7,5};
getCommand(myCommand) will get me:
command = 08
port = 28
value = 475

Thank you.

Ok, you'll probably want to do something different then; or you'll have to use a word long instead of int for value (3 x bytes is too much for an int).

Try some base10 math

iCommand = ((int)command[0] * 10) + (int)command[1]
iValue = ((int)command[4] * 100) + ((int)command[5] * 10) + (int)command[6]
etc. etc.

Edit: I said word, I meant long.

May you explain me more about thous lines please?

Well, if your command inputs are only from 0-9 (it won't work with numbers above 9) then you can combine them by multiplying.

E.g.

TWO DIGITS
Command[0] = 9
Command[1] = 5

9 * 10 = 90
+
5
= 95

THREE DIGITS
command[4] = 2
command[5] = 1
command[6] = 0

2 * 100 = 200
+
1 * 10 = 10
+
0
= 210

The (int) parts cast the byte to an int, because our maths will exceed the capacity of a byte.

If a single input e.g. command[0] can be greater than 9 then you might need to go back to bit shifting and using the long datatype.

Thank you ! :smiley: