Go Down

Topic: Function Declaration Error (Read 2 times) previous topic - next topic

BN.barak

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

Header:
Code: [Select]

void getCommand(byte *command);


cpp:
Code: [Select]

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


Error:
Code: [Select]

\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 :)  :)

cr0sh

Your header needs a class definition, of which your function is declared as a public method.
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

PaulS

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?

BN.barak


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

#include "WProgram.h"

Code: [Select]

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.

Eight

#4
Aug 25, 2010, 11:30 am Last Edit: Aug 25, 2010, 11:39 am by Eight Reason: 1
Just a guess...

Code: [Select]

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

Eight

#5
Aug 25, 2010, 11:48 am Last Edit: Aug 25, 2010, 11:49 am by Eight Reason: 1
I give up already. :D

RemoteC.h
Code: [Select]
#ifndef RemoteC_h
#define RemoteC_h

#include "WProgram.h"

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

#endif


RemotC.cpp
Code: [Select]

#include "RemoteC.h"

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


Works absolutely fine for me.

I suggest posting your complete RemotC.app code.

BN.barak

#6
Aug 25, 2010, 11:59 am Last Edit: Aug 25, 2010, 12:07 pm by BN.barak Reason: 1
Quote
Eight....
THANK YOU!  :D


To late to party..
Still having the error..
Code: [Select]
\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*)




Eight

Lol. If I helped, I don't know how. ;)

BN.barak

I think you for you help :)
Code: [Select]
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);
}


Eight

:D

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[]);

Eight

#10
Aug 25, 2010, 12:17 pm Last Edit: Aug 25, 2010, 12:19 pm by Eight Reason: 1
Although...

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

Code: [Select]

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. :D

BN.barak

#11
Aug 25, 2010, 12:36 pm Last Edit: Aug 25, 2010, 12:37 pm by BN.barak Reason: 1
well, now there are some new errors:
Code: [Select]
\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


Code: [Select]
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.

Eight

#12
Aug 25, 2010, 12:43 pm Last Edit: Aug 25, 2010, 12:44 pm by Eight Reason: 1
Try

Code: [Select]

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.

Eight

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]?

Eight

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.

Code: [Select]

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);
}

Go Up