byte array in the header file

Hi!
I'm making a class for controlling brushless DC motors. I got a large 'pwmSin' array, and want to store this array in the header file:

#include "Arduino.h"

#ifndef BLDC_h
#define BLDC_h

class BLDC
{ 
  public:
    BLDC(uint8_t phase1, uint8_t phase2, uint8_t phase3);
    void step(bool direction);
    
  private:
    uint8_t _phase1;
    uint8_t _phase2;
    uint8_t _phase3;


    const byte pwmSin[48] = {127,110,94,78,64,50,37,26,17,10,4,1,0,1,4,10,17,26,37,50,64,78,94,110,127,144,160,176,191,204,217,228,237,244,250,253,254,253,250,244,237,228,217,204,191,176,160,144,127 };
    
};

#endif

Still I get this error message:

In file included from BLDC.cpp:1:0:
BLDC.h:23: error: too many initializers for 'const uint8_t [48] {aka const unsigned char [48]}'
     const uint8_t pwmSin[48] = {127,110,94,78,64,50,37,26,17,10,4,1,0,1,4,10,17,26,37,50,64,78,94,110,127,144,160,176,191,204,217,228,237,244,250,253,254,253,250,244,237,228,217,204,191,176,160,144,127};
                                                                                                                                                                                                          ^
too many initializers for 'const uint8_t [48] {aka const unsigned char [48]}'

How can I store a byte array in the header, and access it in the cpp file?

hansibull:
How can I store a byte array in the header, and access it in the cpp file?

How can I count 48 array elements without making a counting mistake and insert 49 instead?

Your question is about error-free counting of array elements?
Or what is your question about?

oh! of course! Problem solved! :smiley:

But why do I need to define the length of the array? I don't need that in an ordinary sketch..

Please don't edit the original post.

Why shouldn't one edit the original post? I pasted the wrong error message and just published the post. I didn't got any answers yet either.

You changed the posted code.

You still didn't answered my question WHY i shouldn't edit

You don't need to count. The compiler can do that for you. Just leave the count out of the declaration: int_array[] = {1,2,3};

However, this works best if there is an "end of array marker" like the ending '\0' in a C string. Otherwise you need to do a sizeof(int_array)/sizeof(int_array[0]) calculation to determine the number of elements.

KeithRB:
You don't need to count. The compiler can do that for you. Just leave the count out of the declaration: int_array[] = {1,2,3};

How can I do this (just curious)?

If I enter:
const uint8_t pwmSin[49] = {127, 110, ...}
i get no errors.

if I enter
const uint8_t pwmSin[] = {127, 110, ...}
it seems like it believes that the [] represents a zero:

In file included from BLDC.cpp:1:0:
BLDC.h:22: error: too many initializers for 'const uint8_t [0] {aka const unsigned char [0]}'
     const uint8_t pwmSin[] = {127,110,94,78,64,50,37,26,17,10,4,1,0,1,4,10,17,26,37,50,64,78,94,110,127,144,160,176,191,204,217,228,237,244,250,253,254,253,250,244,237,228,217,204,191,176,160,144,127};
                                                                                                                                                                                                        ^
too many initializers for 'const uint8_t [0] {aka const unsigned char [0]}'

hansibull:
You still didn't answered my question WHY i shouldn't edit

Because the code you have now isn't the same as the code you originally posted.
Is that so very hard to understand?

I just tried it without error. It is a basic language function so I doubt that IDE version matters.

Try deleting the brackets and re-inserting them.

In addition to what AWOL said, if you edit a post, subsequent posts by readers often don't make sense because your edit removed the reason for their comment. It's best if you place any (code) edits in a new post rather than editing the original post.

You now a sin is quite symmetrical? Okay, you "only" store 49 bytes but you can do it with a 1/4 of that. Okay, it comes at the price of some math at run time but simple byte math is pretty fast.

septillion:
You now a sin is quite symmetrical? Okay, you "only" store 49 bytes but you can do it with a 1/4 of that. Okay, it comes at the price of some math at run time but simple byte math is pretty fast.

Right. Native single instruction add or subtract on the processor. It depends how critical your memory usage is.