user68988: 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.

user60431: At the time the constructor of your class is called, its size must be already defined, because the memory allocation takes place before. But you try to give it as a parameter to the constructor. This cannot work.
You have at least these alternatives. (Note: This is an invitation to edit this answer and add more, if you know some serious solution.)
1. Use a template for the size
Please be aware that each different size will generate another implementation in machine code.
template<size_t size>
class myLib {
public:
    inline myLib<size>() {}
private:
    bool data[size];
};

2. Allocate the requested memory dynamically
class myLib {
public:
    inline explicit myLib(size_t size) : data(new bool[size]) {}
    inline ~myLib() {
        delete[] data;
    }
private:
    bool* data;
};

Note: Depending on the version of C++ you're using, you need to consider the Rule of Three (before C++11) or the Rule of Five (beginning with C++11). Since the implementation of the missing methods depends on specific details, it is left as an exercise to the reader.

68988: <p>For a specific project, I need to convert an int to a const int variable type.</p>
<pre><code>int i = 10;
boolean ShiftRegister[i] //Throws error

const int i = 10;
boolean ShiftRegister[i]// Works Fine
</code></pre>
<p>as i am making my own custom library where the size of boolean can be defined by creating an object by the user</p>
<pre><code>myLib Library(20); // user defined boolean size
</code></pre>
<p>and the size is stored to a struct like this as it can't directly be converted to a const int.</p>
<p>The header file ...</p>
<pre><code>#ifndef myLib_h
#define myLib_h
#include &quot;Arduino.h&quot;

class myLib{

public:
myLib(int input);
private:
int input;

};
#endif
</code></pre>
<p>the C++ code</p>
<pre><code>#include &quot;myLib.h&quot;
#include &quot;Arduino.h&quot;

 struct Data {
  int BoolSize;
 }Data[0];

 myLib::myLib(int input){
 Data[0].BoolSize=input
 }
 
 const int boolSize = Data[0].BoolSize;

 bool DataBoolean[boolSize];
</code></pre>
<p>Whenever i run this library, it throws an error untill i dont predefine the boolean size in cpp code like this..</p>
<pre><code>bool DataBoolean[20];
</code></pre>
<p>that means there is something error converting the int to const int in this line</p>
<pre><code>const int boolSize = Data[0].BoolSize;
</code></pre>
<p>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</p>
<p>turn this struct variable</p>
<pre><code>Data[0].BoolSize;
</code></pre>
<p>into a const variable and assign to it like this without any errors</p>
<pre><code>const int boolSize = Data[0].BoolSize;
</code></pre>
<p>so how can i convert an integer to a const int so that i can continue to my project?</p>
<p>any helps please? thanks for your kind support.</p>
 60431: <p>At the time the constructor of your class is called, its size must be already defined, because the memory allocation takes place before. But you try to give it as a parameter to the constructor. This cannot work.</p>
<p>You have at least these alternatives. <em>(Note: This is an invitation to edit this answer and add more, if you know some serious solution.)</em></p>
<h3>1. Use a template for the size</h3>
<p>Please be aware that each different size will generate another implementation in machine code.</p>
<pre class="lang-cpp prettyprint-override"><code>template&lt;size_t size&gt;
class myLib {
public:
    inline myLib&lt;size&gt;() {}
private:
    bool data[size];
};
</code></pre>
<h3>2. Allocate the requested memory dynamically</h3>
<pre class="lang-cpp prettyprint-override"><code>class myLib {
public:
    inline explicit myLib(size_t size) : data(new bool[size]) {}
    inline ~myLib() {
        delete[] data;
    }
private:
    bool* data;
};
</code></pre>
<p><em>Note: Depending on the version of C++ you're using, you need to consider the <a href="https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)" rel="nofollow noreferrer">Rule of Three</a> (before C++11) or the <a href="https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming)#Rule_of_Five" rel="nofollow noreferrer">Rule of Five</a> (beginning with C++11). Since the implementation of the missing methods depends on specific details, it is left as an exercise to the reader.</em></p>
