I understand the error with my code. I'm trying to initialize an array within a class, which is not allowed because
by wrapping it into a class, your supposed constants are no longer names that refer to an object with a fixed value given at initializing the constant. Instead, you are now declaring constant data members, which are like non-constant data members, and exist in each instance in that class on their own. The value you provide is nothing more than a default value for initializing the constant member in the constructor. error: too many initializers for const
Morse Code characters can be up to six characters long with units being the DOTS or DASHES. Accordingly, I have an array that I want hold up to six spots. The catch, is that I'm using an Arduino Uno, so memory is a concern. How can I write my code to be able to do this with the lowest memory usage, or simply a working example of what I'm trying to accomplish without resorting to the STL. code.h
#include "Arduino.h"
const short DOT = 1000 / 2;
const short DASH = 3000 / 2;
class Code
{
public:
Code();
Code(short short1);
Code(short short1, short short2);
Code(short short1, short short2, short short3);
Code(short short1, short short2, short short3, short short4);
Code(short short1, short short2, short short3, short short4, short short5);
Code(short short1, short short2, short short3, short short4, short short5, short short6);
~Code();
private:
short letterMakeUp[];
};
code.cpp
#include "Arduino.h"
#include "code.h"
Code::Code()
{
}
Code::Code(short short1) : letterMakeUp{ short1 }
{
};
Code::Code(short short1, short short2) : letterMakeUp{short1, short2}
{
}
Code::Code(short short1, short short2, short short3) : letterMakeUp{short1, short2, short3}
{
}
Code::Code(short short1, short short2, short short3, short short4) : letterMakeUp{ short1, short2, short3, short4 }
{
}
Code::Code(short short1, short short2, short short3, short short4, short short5) : letterMakeUp{ short1, short2, short3, short4, short5 }
{
}
Code::Code(short short1, short short2, short short3, short short4, short short5, short short6) : letterMakeUp{ short1, short2, short3, short4, short5, short6 }
{
}
characters.h
Code Letters[26] =
{
{ DOT, DASH },
{ DASH, DOT, DOT, DOT },
{ DASH, DOT, DASH, DOT },
{ DASH, DOT, DOT },
{ DOT },
...
};
Aucun commentaire:
Enregistrer un commentaire