Need help creating an Object.

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.

Here is what I have.

class FONT {
  public:
    const uint8_t iRows,   iCols;
    const uint8_t iMinVal, iMaxVal;
    const uint8_t **BitMap;
};

class FONT5X8 : FONT {
  public:
  static const uint8_t iRows=8; 
  static const uint8_t iCols=5;
  static const uint8_t iMinVal=0x41;
  static const uint8_t iMaxVal=0x5A;
  static const uint8_t BitMap[][5] = {
    {0b01111110, // 41 A       //  .@@@@@@.
     0b00010001,               //  ...@...@
     0b00010001,               //  ...@...@
     0b00010001,               //  ...@...@
     0b01111110},              //  .@@@@@@.
                               
    {0b01111111, // 42 B       //  .@@@@@@@
     0b01001001,               //  .@..@..@
     0b01001001,               //  .@..@..@
     0b01001001,               //  .@..@..@
     0b00110110},              //  ..@@.@@.

...

    {0b00000111, // 59 Y       //  .....@@@
     0b00001000,               //  ....@...
     0b01110000,               //  .@@@....
     0b00001000,               //  ....@...
     0b00000111},              //  .....@@@
                               
    {0b01100001, // 5a Z       //  .@@....@
     0b01010001,               //  .@.@...@
     0b01001001,               //  .@..@..@
     0b01000101,               //  .@...@.@
     0b01000011}               //  .@....@@
  };
};

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.

A Real n00b question but are they in scope?

Doc

A Real n00b question but are they in scope?

Are what in scope?

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.

@ Paul, Thank You... I am still learning and what you say makes perfect sense.

Doc

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.

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.

pylon:

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.

That is the explanation, what is the solution?

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.

RandallR:
That is the explanation, what is the solution?

Define and initialise the class static data in the implementation file, similar to the way you define the class methods.

I was attempting to define a class (or structure) that was all "static" and would not need to be instanciated.

I wanted to access the bitmap with "FONT5X8::BitMap" and not "instance5x8.BitMap"

RandallR:
I was attempting to define a class (or structure) that was all "static" and would not need to be instanciated.

You can do that using static class members, as you have described.

The static members should be defined and initialised in the implementation file.

was attempting to define a class (or structure) that was all "static" and would not need to be instanciated.

Why? If you don't need a class, so you can create instance, don't define a class. You can still use .h and .cpp files.