I am trying to create an object that describes a font. I am trying to start with something simple with a fixed pitch font but I may try to support a proportional font later.
When I try to compile this, I get the error
error: a brace-enclosed initializer is not allowed here before ‘{’ token
error: invalid in-class initialization of static data member of non-integral type ‘const uint8_t [][5] {aka const unsigned char [][5]}’
So my syntax is wrong but I believe that my desire is clear.
In addition I will want to store this object in flash to preserve RAM. However, I am looking to jump one hurdle at a time.
Don't do the variable initialization inside the class definition if you want to store the font in the flash. As far as I know the PROGMEM marker does not work for class member variables, even if they are constant.
Initialization of variables is never done in the class definition in the header file. It is always done in the source file. Any attempt to initialize variables in the class definition in the header file results in syntax errors.
PaulS:
Initialization of variables is never done in the class definition in the header file. It is always done in the source file. Any attempt to initialize variables in the class definition in the header file results in syntax errors.
There appear to me some exceptions to that. The statement
static const uint8_t iRows=8;
appears to be allowed. What is not allowed is to initialize the array.
An array is a pointer in C. A constant integer variable is replaced by the compiler by it's value in the resulting code. It cannot do that with the array.
An array is a pointer in C. A constant integer variable is replaced by the compiler by it's value in the resulting code. It cannot do that with the array.
Assigning the value in the constructor instead of in the declaration?
I outlined my solution in an earlier post, so you're able to store the whole font definition in PROGMEM and not in RAM but with that solution you're not done with the class definition but you have to have a complete font class and once you need the font data you have to read it from flash.