Do you think I haven't encountered this? I haven't quite figured out how it works. Here's the thing. But as it turns out, I don't need a singleton. So I'll make do with static members.
ALXIMIKS:
How can we talk about paternals if you don't know the basics, you couldn't even create a static class field correctly.
If you know how, you may correct it. Yesterday I wrote according to documentation. But there are a lot of errors too. Like this:
struct Symbol_Properties
{
staticdatetime gdt_Quote; // Время поступления последней котировкиstaticdouble gda_Price [2]; // Текущие рыночные цены (0 - Bid, 1- Ask)staticdouble gd_Spread; // Размер спреда в пунктахstaticdouble gd_Swap; // Свопstaticdouble gd_Comission; // Комиссияstaticdouble gd_Pt; // Величина одного пунктаstaticint gi_Digits; // Количество знаков в цене после запятойstaticint gi_StopLevel; // Минимально-допустимый уровень стоп-лосса/тейк-профита в пунктахstaticint gi_FreezLevel; // Уровень заморозки ордеров в пунктах
};
int Symbol_Properties::gdt_Quote = 0;
int Symbol_Properties::gda_Price = 0;
int Symbol_Properties::gd_Spread = 0;
int Symbol_Properties::gd_Swap = 0;
int Symbol_Properties::gd_Comission = 0;
int Symbol_Properties::gd_Pt = 0;
int Symbol_Properties::gi_Digits = 0;
int Symbol_Properties::gi_StopLevel = 0;
int Symbol_Properties::gi_FreezLevel = 0;
I threw the wrong one off. Anyway, the current version is correct here:
struct Symbol_Properties
{
staticdatetime gdt_Quote; // Время поступления последней котировкиstaticdouble gda_Price [2]; // Текущие рыночные цены (0 - Bid, 1- Ask)staticdouble gd_Spread; // Размер спреда в пунктахstaticdouble gd_Swap; // Свопstaticdouble gd_Comission; // Комиссияstaticdouble gd_Pt; // Величина одного пунктаstaticint gi_Digits; // Количество знаков в цене после запятойstaticint gi_StopLevel; // Минимально-допустимый уровень стоп-лосса/тейк-профита в пунктахstaticint gi_FreezLevel; // Уровень заморозки ордеров в пунктах
};
datetime Symbol_Properties::gdt_Quote = 0;
double Symbol_Properties::gda_Price [2] = {0.0, 0.0};
double Symbol_Properties::gd_Spread = 0;
double Symbol_Properties::gd_Swap = 0;
double Symbol_Properties::gd_Comission = 0;
double Symbol_Properties::gd_Pt = 0;
int Symbol_Properties::gi_Digits = 0;
int Symbol_Properties::gi_StopLevel = 0;
int Symbol_Properties::gi_FreezLevel = 0;
I guess now I have to refer to each static variable by such a long name?
Symbol_Properties::gd_Spread = 0;
Or is it easier to implement it so that after description of variable initialization structure when it' s initialized the corresponding static member should be assigned to some variable of type:
double Spread = Symbol_Properties::gd_Spread = 0;
And then in the code refer to the corresponding static variables by this variable, right?
Yeah, well... The main thing is thatVadim knows :)))))
Yeah, that's the normal kind of dialogue:
Q: My friends recommended some candy to me. It's just what I need!
Me: (Puzzled... What does this have to do with candy? Maybe B is going to a friend's birthday party or wants to treat the kids, maybe his own or someone else's? Maybe he went into business and is now selling candy. Maybe it was the last candy in Belarus and B is now a monopolist. What if B missed the candy? A lot of other thoughts ran through my head on the subject of "why candy and what to do with it". Once again, as before with B, my telepathic abilities failed me. Nothing came to mind).
Not a clue.
Just in case. It's rude to post dialogues without the consent of everyone involved in the conversation. It's mean-spirited.
Convenience... After all, if these variables are used in a single instance, why should I create an object? Besides, it's much more convenient to read the code when referring to a variable, if VARIABLE.VARIABLE NAME.
ALXIMIKS:
2. There are two ways of accessing class static fields (structure is a class with public access by default and inheritance)
(a) via the class namespace - e.g.Symbol_Properties::gd_Spread
(double Spread = Symbol_Properties::gd_Spread) - theSpread value becomes equal togd_Spread from theSymbol_Propertiesclass
(double Spread = Symbol_Properties::gd_Spread =0)- thegd_Spread value from classSymbol_Properties and theSpreadvalue becomes equal to 0
Exactly! That's why I did it that way. I immediately initialize the variable which refers to the variable of this structure by zero and then it's stored in memory permanently. Which is logical, because these variables are needed in a single instance. That's why there's no reason to create different object in this case. After all, it is logical... Don't you agree with me?
ALXIMIKS:
b) Create a class object (e.g.Symbol_Properties obj; ) and refer to it as a normal class field through this object
Then the variables will not be static, and there is no guarantee that they will not retain their values as the program runs.
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.
What paternas can we talk about if you don't know the basics, you couldn't even create a static class field correctly.
(there are a lot of articles about singleton on hobber, what it's for, how to do it and what's wrong with it).
Singleton or a static class?Using the singleton pattern
(there are lots of articles about singleton on the hubrabs and what it's for, and how, and what's wrong with it)
Singleton or static class?Using Singleton pattern.
Do you think I haven't encountered this? I haven't quite figured out how it works. Here's the thing. But as it turns out, I don't need a singleton. So I'll make do with static members.
How can we talk about paternals if you don't know the basics, you couldn't even create a static class field correctly.
If you know how, you may correct it. Yesterday I wrote according to documentation. But there are a lot of errors too. Like this:
What's next?
I threw the wrong one off. Anyway, the current version is correct here:
I guess now I have to refer to each static variable by such a long name?
Symbol_Properties::gd_Spread = 0;Or is it easier to implement it so that after description of variable initialization structure when it' s initialized the corresponding static member should be assigned to some variable of type:
And then in the code refer to the corresponding static variables by this variable, right?
Yeah, well... The main thing is thatVadim knows :)))))
Yeah, that's the normal kind of dialogue:
Q: My friends recommended some candy to me. It's just what I need!
Me: (Puzzled... What does this have to do with candy? Maybe B is going to a friend's birthday party or wants to treat the kids, maybe his own or someone else's? Maybe he went into business and is now selling candy. Maybe it was the last candy in Belarus and B is now a monopolist. What if B missed the candy? A lot of other thoughts ran through my head on the subject of "why candy and what to do with it". Once again, as before with B, my telepathic abilities failed me. Nothing came to mind).
Not a clue.
1. What is all this for?
2. There are two ways to access the static fields of a class (the structure is a public access class by default and inheritance):
(a) Through the class namespace - e.g.Symbol_Properties::gd_Spread
(double Spread = Symbol_Properties::gd_Spread) - theSpread value becomes equal togd_Spread from theSymbol_Propertiesclass
(double Spread = Symbol_Properties::gd_Spread =0) value ofgd_Spread fromSymbol_Properties class andSpreadvalue becomes equal to 0
b) create an object of class (for example,Symbol_Properties obj; ) and refer to it as a usual field of the class through this object
(double Spread = obj.gd_Spread)
(double Spread = obj.gd_Spread =0)
1. What's it all for?
Convenience... After all, if these variables are used in a single instance, why should I create an object? Besides, it's much more convenient to read the code when referring to a variable, if VARIABLE.VARIABLE NAME.
2. There are two ways of accessing class static fields (structure is a class with public access by default and inheritance)
(a) via the class namespace - e.g.Symbol_Properties::gd_Spread
(double Spread = Symbol_Properties::gd_Spread) - theSpread value becomes equal togd_Spread from theSymbol_Propertiesclass
(double Spread = Symbol_Properties::gd_Spread =0)- thegd_Spread value from classSymbol_Properties and theSpreadvalue becomes equal to 0
Exactly! That's why I did it that way. I immediately initialize the variable which refers to the variable of this structure by zero and then it's stored in memory permanently. Which is logical, because these variables are needed in a single instance. That's why there's no reason to create different object in this case. After all, it is logical... Don't you agree with me?
b) Create a class object (e.g.Symbol_Properties obj; ) and refer to it as a normal class field through this object
STATE VARIABLE did not please me, because they are used in different classes. So I sort of grouped them together.
Constants are not liked because constants do not change their values, while these variables should be able to change their values.