Example: The class (library) uses array of default fixed size. Let's say 64 bytes. In the program, however, you may need bigger size, lets say 128 bytes. What would be the best approach, if you don't want to rewrite the library every time?
I tried to demonstrate this by following WRONG code (using #ifndef
#define
):
// myClass.h *****************************************
#ifndef myClass_h
#define myClass_h
#ifndef EXAMLPE
#define EXAMLPE 64
#endif
class myClass{
...
private:
byte myArray[EXAMLPE]; // Use EXAMLPE to allocate array
}
#endif
// Program.ino ***************************************
// Override the default value without modifying the library
#define EXAMLPE 128
#include "myClass.h"
// this does not work because of different scope, says compiler
EDIT: I want make fixed size array as it is easy and it is considered as good practise on 2kb RAM platform
EDIT 2: I don't understand all the arguing in the comment and also why my question is down rated. I'm not a great programmer of course, I do not know anything about vectors, nor templates, and that's why I'm asking here for help.
I'm looking for a method, how to set fixed size array in library from main code in compile time.
And finally: Does anyone know why do I get compile error EXAMPLE was not declared in this scope
when I delete #ifndef EXAMPLE ... #endif lines from header? Isn't it suppose to be scope independent?