You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Thank you all for the support.
Seems that the issue was the lack of default constructor for the trade_record strucut. Bellow is the compiling code.
Onde more questions if possible. Is it possible to initialize a struct without using a default constructor, the ideia here is to guarantee some invariants possible using construct overloads. Or for this scenario would be better to use classes instead?
Below is the example an exemple of the ideia:
To summarize, the goal here is to find a idiomatic way in MQL5, to avoid creating objects that are in a inconsistent state, like in the default constructor of trade_record.
To summarize, the goal here is to find a idiomatic way in MQL5, to avoid creating objects that are in a inconsistent state, like in the default constructor of trade_record.
If you are worried about inconsistent initialization, you should code it so it can never happen. Either make sure the default constructor has the right defaults, or use an overloaded constructor and pass the params you want. Or simplest of all, create a method to set the values you want which can be called anytime, even later in the program (this is my preference as per my first example).
If you are worried about inconsistent initialization, you should code it so it can never happen. Either make sure the default constructor has the right defaults, or use an overloaded constructor and pass the params you want. Or simplest of all, create a method to set the values you want which can be called anytime, even later in the program (this is my preference as per my first example).
I get your ideia. Since the default constructor puts trade_record in a inconsistent state, I would like to not use the default constructor approach. Are there any other way to not use default constructor?
The goal is to make impossible to create an inconsistent trade_record. Are there any other idiomatic MQL5 solution for this scenario?
I was able to explain my point about the make impossible to create inconsistent state? And find idiomatic MQL5 solutions to avoid it?
Is it possible to initialize a struct without using a default constructor, the ideia here is to guarantee some invariants possible using construct overloads. Or for this scenario would be better to use classes instead?
I get your ideia. Since the default constructor puts trade_record in a inconsistent state, I would like to not use the default constructor approach. Are there any other way to not use default constructor?
The goal is to make impossible to create an inconsistent trade_record. Are there any other idiomatic MQL5 solution for this scenario?
I was able to explain my point about the make impossible to create inconsistent state? And find idiomatic MQL5 solutions to avoid it?
With structures you don't need to have an any constructors or methods unless you want to - the choice is yours.
I hope this code explains it (I did not create any example with constructors as that is shown in the earlier examples)
Awesome, thank all for the iterations.
Starting to realize, that the goal is something more OOP, possible using encapsulation of the members, below is a working example.
Using this approach is impossible to get an inconsistent state of TradeRecord.
So, trying to improve it, using interfaces, starting getting some errors, code below:
Follow as attachment the compilation error.
It worked returning a Pointer of the interface ITradeCase
Any tips in make it more idiomatic are welcome.
Starting to realize, that the goal is something more OOP, possible using encapsulation of the members, below is a working example.
As you want it to be more OOP, then use objects from the start - we have explored this topic quite extensively, so to conclude I suggest you embed the struct in an object.
The passive structure is very handy if you want to re-use a common set of fields in other places.
Small example attached to demonstrate the array, objects, structure and function all speak the same language - add/removing fields across all these is easy.