For a specific project, I need to convert an int to a const int variable type.
int i = 10;
boolean ShiftRegister[i] //Throws error
const int i = 10;
boolean ShiftRegister[i]// Works Fine
as i am making my own custom library where the size of boolean can be defined by creating an object by the user
myLib Library(20); // user defined boolean size
and the size is stored to a struct like this as it can't directly be converted to a const int.
The header file ...
#ifndef myLib_h
#define myLib_h
#include "Arduino.h"
class myLib{
public:
myLib(int input);
private:
int input;
};
#endif
the C++ code
#include "myLib.h"
#include "Arduino.h"
struct Data {
int BoolSize;
}Data[0];
myLib::myLib(int input){
Data[0].BoolSize=input
}
const int boolSize = Data[0].BoolSize;
bool DataBoolean[boolSize];
Whenever i run this library, it throws an error untill i dont predefine the boolean size in cpp code like this..
bool DataBoolean[20];
that means there is something error converting the int to const int in this line
const int boolSize = Data[0].BoolSize;
so what i want is, i dont want to predefine the boolean size in the cpp code. i would rather like to define boolean size by creating an object(where the code crashed), storing the size to a structure then assigning the structure integer to the const int variable. I need an efficiant way to
turn this struct variable
Data[0].BoolSize;
into a const variable and assign to it like this without any errors
const int boolSize = Data[0].BoolSize;
so how can i convert an integer to a const int so that i can continue to my project?
any helps please? thanks for your kind support.
struct Data { int BoolSize; } Data[0];
declares an array of zero elements. You need to change that 0 to (at least) a 1.