i'm facing a little issue with a new class i'm trying to write.
Here is the description for my class :
class TERMINALSYNC {
public:
TERMINALSYNC(void);
int runcommand(int);
void showhelp(); //show all available commands
void showtime();
void showdate();
void showfullconf();
void sendata(char msg);
private:
const char* commandList[][91];
int debug=true; //use to display debug info
};
And the corresponding cpp.
TERMINALSYNC::TERMINALSYNC()
{
const char* this->commandList[][91] =
{
/*
* Array use this format :
* {"Command","hint "}
*/
{"HELP", "Display command information"},
{"SYNC", "description label 1"},
{"SHOWDATE", "description label 2"},
{"SHOWTIME", "display current time "},
{"SHOWALL", "Show current config from memory"},
};
On compiling, it show me this error message :
C:\Users\xxxxx\Dropbox\Arduino\libraries\terminalsync\terminalsync.cpp:10:14: error: expected unqualified-id before 'this'
const char* this->commandList[][91] =
^
C:\Users\xxxxx\Dropbox\Arduino\libraries\terminalsync\terminalsync.cpp:10:14: error: expected initializer before 'this'
C:\Users\xxxx\Dropbox\Arduino\libraries\terminalsync\terminalsync.cpp:71:1: error: expected '}' at end of input
}
^
I do not understand why. I check some official library and "this->" keyword is used (for methods, not attributes but i think i'ts the same !).
You are trying to declare a new variable in the constructor. You should not be doing that. There are no shortcuts for populating an array that you have already declared.
You are deferencing a pointer with -> which makes no sense at all in a declaration. Declare the
variable in the class definition like any other variable.