Pages: [1] 2   Go Down
Author Topic: Function Declaration Error  (Read 1546 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Header:
Code:
void getCommand(byte *command);

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

Error:
Code:
\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 smiley  smiley
Logged


Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 5519
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

#include "WProgram.h"

Code:
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.
Logged


UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a guess...

Code:
\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.
« Last Edit: August 25, 2010, 04:39:37 am by Eight » Logged

UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I give up already. smiley-grin

RemoteC.h
Code:
#ifndef RemoteC_h
#define RemoteC_h

#include "WProgram.h"

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

#endif

RemotC.cpp
Code:
#include "RemoteC.h"

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

Works absolutely fine for me.

I suggest posting your complete RemotC.app code.
« Last Edit: August 25, 2010, 04:49:41 am by Eight » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Eight....
THANK YOU!  smiley-grin

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


« Last Edit: August 25, 2010, 05:07:06 am by BN.barak » Logged


UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lol. If I helped, I don't know how. smiley-wink
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you for you help smiley
Code:
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);
}
Logged


UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

smiley-grin

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

UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Although...

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

Code:
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-grin
« Last Edit: August 25, 2010, 05:19:46 am by Eight » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

well, now there are some new errors:
Code:
\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:
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.
« Last Edit: August 25, 2010, 05:37:12 am by BN.barak » Logged


UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try

Code:
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.
« Last Edit: August 25, 2010, 05:44:19 am by Eight » Logged

UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

UK
Offline Offline
Sr. Member
****
Karma: 0
Posts: 304
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1] 2   Go Up
Jump to: