Greetings, I am trying to create a static const double array as a class member. It is basically part of a lookup table that I want to target into FLASH. Not really sure what is wrong here, as my code compiles fine in a different compiler (IAR). Here is from my *.h file (I replaced most of the code with "..." so you could easily focus on the culprit member) :
You are declaring the array, incorrectly since there is no size defined, in the header file and again in the source file. That is NOT allowed. Declared it in the header file. Initialize it in the source file. And, no, you can't initialize it using the declare and initialize in one step process in the header file.
Well I don't have anything above the array initialization except #include statements (no silly errors like your example)....but if you say that there is nothing illegal about the code I provided then that is at least helpful to me in that I should look elsewhere for an error (maybe those included files). Maybe it's a case of a missing bracket or semi-colon.
Something still seems suspicious to me in the fact that I could compile the code fine in IAR. Oh well, thank you very much friendly Arduino community.
I also think you are better off explicitly defining the size of the array in the class declaration. The definition of the class functions don't all have to be in the same source code file, I can forsee issues if you want to have a static class member where the size might not be known within the compilation scope of a particular source code file.
michinyon:
I recall some funnybusiness with the static keyword, you can have it it the header file or the cpp file, but not both.
static can only go on declarations, not definitions, in other words it cannot go in the .cpp if/or outside the class. Think of them as 'with reference' to the scope they are declared in.
struct Foo{
typedef int A;
static A a;
};
static Foo::A a = 0;
Foo::A Foo::a = 0;
Foo::a is static to Foo, a is static to the file & not part of the class.