[RESOLVED] error: expected ';' at end of member declaration

Hi all,

I have a compilation error I don't understand for a little tiny class. At compilation it complains that he needs a semicolon.

Have you any idea why ?

// tools.h

#ifndef daap_tools_h
#define daap_tools_h
class Tools {
  public:
  static int toInt(char c);
  static char* toTwoChar(byte b);
};
#endif
// tools .cpp

#include "tools.h"

int Tools::toInt(char c) {
  return (int)(c - 48);
}

char* Tools::toTwoChar(byte b) {
  byte dizaines = b / 10 ;
  byte unites = b - dizaines*10;
  char res[3] = {'0' + dizaines, '0' + unites, '\0'};
  return res;
}

You can see complete compilation error here : GDB online Debugger | Code, Compile, Run, Debug online C, C++

Thanks,
Phaust

You get 3 errors, none of which are probably what you are trying to do, but all 3 are for the line

static char* toTwoChar(byte b);

Looking at this, I can see this is incorrect syntax for a function pointer, if that is what you are trying to do, but I am not sure what you are trying to do with this line.

};
#endif

why is that semicolon there? what does it do?

char res[3] = {'0' + dizaines, '0' + unites, '\0'};
  return res;

Oops

[quote author=Geek Emeritus link=msg=4208920 date=1560432097]

};
#endif

why is that semicolon there? what does it do?
[/quote] Ends the class.

Class names end with a semicolon.

Perehama:
You get 3 errors, none of which are probably what you are trying to do, but all 3 are for the line

static char* toTwoChar(byte b);

Looking at this, I can see this is incorrect syntax for a function pointer, if that is what you are trying to do, but I am not sure what you are trying to do with this line.

The method transforms a byte to its string (char*) equivalent. This is not a function pointer but a function returning a char pointer (this is what I want, I would like to do).

But you're returning a pointer to a non-static local variable, so by the time you use it, the memory it points to could already have been repurposed.

PhaustSceptic:
The method transforms a byte to its string (char*) equivalent. This is not a function pointer but a function returning a char pointer (this is what I want, I would like to do).

You want to pass the value of the byte or the address of the byte?

Except memory usage problems or other type of execution problems (I will quickly checks that :D) why the code does not compile ?

I add the static keyword to be able to access the method without the need of instantiate the class. But removing it does not change the compilation error.

I found it !

I need to add the following include in order to get access to the byte type…

#include <arduino.h>

Now, removing programming errors :smiley:

Thanks all,
Phaust.

The correct filename is Arduino.h. Although you can may (depending on where you use it) get away with arduino.h on a filename case-insensitive OS like Windows, this will not work on a case sensitive OS like Linux. Correct filename case is required for #include directives in Arduino sketches even on Windows. So it's best to always use the proper filenames.