If you want a non-dynamic array you have to make sure to specify exactly the same number of elements that's used in the initializer list, otherwise you'll get this error.
To avoid that hassle I suggest to always go with dynamic arrays when it comes to initialize it by a list.
The advantage is that you don't have to count your initializers and adapt that array size everytime you change that list.
The disadvantage is that a dynamic array uses up more memory - 52 bytes - for the dynamic array properties. I guess you can live with this in most of the cases.
Thanks for detailed explanation lippmaje.
Well while making it static, defining ArrayResize was the problem in my mind (as I did not knew, how I will for a member Array).
now explanation has made everything crystal clear.
Can you suggest some structure and how to fill it & call it. The object is to store static Camarilla Pivot Levels (R5,R4,R3,R2,R1,PP,S1,S2,S3,S4 and S5) and change dynamically level values every new day start.
In simple language, I am looking to create Column[1] as List of Pivot Levels (to be able to select level) and Colum[2] for 'level values' which shall change everyday. No need to keep history data.
It is some how similar to Fibonacci structure we used above, but I am finding difficult to handle string values of PivotLevels.
Make a array in the constructor and copy to the member array.
Do it the hard way.
Hi William
I have a similar problem, and wish to follow your second option but am getting stuck at the missing default value for the passed array:
class CValue{
private:
int m_Dec;
string m_Binary;
bool m_BoolArray[];
int m_Exponent;
public:
CValue(int aDec=NULL, string aBinary="", bool &aBoolArray[]=???, int aExponent=NULL) {
// Happy to loop through aBoolArray here to populate m_BoolArray (although if you have a better idea please let me know)
Init(aDec, aBinary, aExponent);
}
void Init(int aDec=NULL, string aBinary="", int aExponent=NULL) {
// Set parameters
m_Dec =aDec;
m_Binary =aBinary;
m_Exponent =aExponent;
}
};
Please help! The class is to enable the representation of an array of boolean values as a decimal (via binary) number for optimisation of large (variable) numbers of boolean parameters
William Roeder #: You can't default a reference. Arrays must be passed by reference. Write two constructors.
I am so sorry, but I do not understand your last sentance - the first I suspected, the second I knew. But I still do not understand how to make this code reusable in terms of being able to define a class array without defining a global array prior to instantiating the object and iterating through it in the constructor... or is this what you meant i.e.
class CValue{
private:
int m_Dec;
string m_Binary;
bool m_BoolArray[];
int m_Exponent;
public:
CValue(int aDec=NULL, string aBinary="", int aExponent=NULL) {
ArrayResize(m_BoolArray,ArraySize(gArray));
for(i=0;i<ArraySize(gArray);i++{
m_BoolArray[i] = gArray[i];
}
Init(aDec, aBinary, aExponent);
}
void Init(int aDec=NULL, string aBinary="", int aExponent=NULL) {
// Set parameters
m_Dec =aDec;
m_Binary =aBinary;
m_Exponent =aExponent;
}
};
bool gArray[];
// initialise gArray and assign values here
CValue value1();
also, should the Init declaration start with
void Init(int aDec=NULL, string aBinary="", int aExponent=NULL)
or
void Init(int aDec, string aBinary, int aExponent)
given that default values are given in the declaration of the constructor... I suppose they should remain in the Init declaration to allow reuse of the function after the Class instance is loaded?
William Roeder #: You can't default a reference. Arrays must be passed by reference. Write two constructors. Andrew Thompson #: I am so sorry, but I do not understand your last sentance - t
CValue(int aDec, string aBinary, bool &aBoolArray[], int aExponent=NULL) { // use array to initialize class
CValue(int aDec=NULL, string aBinary="", int aExponent=NULL) { // no array passedbool aBoolArray[]={ 0, 1, …]; // default array.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
If you want a non-dynamic array you have to make sure to specify exactly the same number of elements that's used in the initializer list, otherwise you'll get this error.
To avoid that hassle I suggest to always go with dynamic arrays when it comes to initialize it by a list.
The advantage is that you don't have to count your initializers and adapt that array size everytime you change that list.
The disadvantage is that a dynamic array uses up more memory - 52 bytes - for the dynamic array properties. I guess you can live with this in most of the cases.
Thanks for detailed explanation lippmaje.
Well while making it static, defining ArrayResize was the problem in my mind (as I did not knew, how I will for a member Array).
now explanation has made everything crystal clear.
Thanks a lot once again.
Hi lippmaje
Can you suggest some structure and how to fill it & call it. The object is to store static Camarilla Pivot Levels (R5,R4,R3,R2,R1,PP,S1,S2,S3,S4 and S5) and change dynamically level values every new day start.
In simple language, I am looking to create Column[1] as List of Pivot Levels (to be able to select level) and Colum[2] for 'level values' which shall change everyday. No need to keep history data.
It is some how similar to Fibonacci structure we used above, but I am finding difficult to handle string values of PivotLevels.
Thanks in advance for you support and help.
You didn't declare your constructor in the class.
The initialization list only works when you declare an array. You can not use it at runtime.
Hi William
I have a similar problem, and wish to follow your second option but am getting stuck at the missing default value for the passed array:
Please help! The class is to enable the representation of an array of boolean values as a decimal (via binary) number for optimisation of large (variable) numbers of boolean parameters
You can't default a reference. Arrays must be passed by reference. Write two constructors.
I am so sorry, but I do not understand your last sentance - the first I suspected, the second I knew. But I still do not understand how to make this code reusable in terms of being able to define a class array without defining a global array prior to instantiating the object and iterating through it in the constructor... or is this what you meant i.e.
also, should the Init declaration start with
or
given that default values are given in the declaration of the constructor... I suppose they should remain in the Init declaration to allow reuse of the function after the Class instance is loaded?
Andrew Thompson #: I am so sorry, but I do not understand your last sentance - t