
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
1. new operator returns a pointer, of course, developers made a mess with implicit dereferencing, so your version works, but it's better not to get hung up on undocumented things.
2. Of course, we don't have C++, but it's very similar, so initialization lists (I don't know about efficiency) are kosher.
Checked, yes your option works, and logically it's more correct:
2019.08.31 22:07:35.196 tst (EURUSD,H1) Strategy_1::Strategy_1
2019.08.31 22:07:35.196 tst (EURUSD,H1) Context::Context
2019.08.31 22:07:35.196 tst (EURUSD,H1) Strategy_2::Strategy_2
2019.08.31 22:07:35.196 tst (EURUSD,H1) Context::Context
2019.08.31 22:07:35.196 tst (EURUSD,H1) Strategy_1::Algorithm
2019.08.31 22:07:35.196 tst (EURUSD,H1) Strategy_2::Algorithm
2019.08.31 22:07:35.197 tst (EURUSD,H1) Strategy_1::Algorithm
The pointer and the object created at initialization were not lost, and the method in the interface did not substitute the methods of the classes 1 and 2 - everything seems to work as planned
How can I avoid repetitive code sections during initialisation? - in the constructor you cannot
How can I avoid repetitive code sections during initialisation? - in the constructor, you can't
Instead of interface, you make a regular class. There you put *m and make method bool SomeMethod {if (CheckPointer(m)) return false; m=new...; return true;}
No, I need the interfes - it's very cool that I won't need to pull everything at every tick - I'll make one call of one strategy per one tick - in general I like config of all this so far, it seems it was necessary to solve my problem this way:
I tweaked my example a bit - it works, but it should look like this:
but if I remove the body of theCStrategy::Algorithm(void) method, there will be an error: 'Algorithm' -the function must have a body
Why is it an error? - because I declare the CStrategy::Algorithm(void) method with the modifier virtual
I tweaked my example a bit - it works, but it should look like this:
but if I remove the body of the CStrategy::Algorithm(void) method, there will be an error: 'Algorithm' - the function must have a body
Why is it an error? - because I declare the CStrategy::Algorithm(void) method with the modifier virtual
virtual void Algoritm()=0;
No, that won't work either. If you declare an abstraction, be kind enough to implement it.
I think the compiler perceives the Algorithm() method from the interface and the declared virtual void Algorithm() as different methods because of the virtual modifier
An abstract method must be implemented in descendants. Once again, there's no need to implement it.
I need interfaces because it is convenient for me to declare different behaviour for 6 strategies depending on Expert Advisor settings (there are not so many strategies but order systems)
right now:
I want to minimize the body of Algorithm() methods - if I write the base class correctly - in my example, class CStrategy, then the Algorithm() itself will contain 5-10 lines at most
How should I write this code without an interface? - Now everything is brief and there will only be left to pull the algorithms themselves strategies every tick or less frequently
как этот код без интерфейса написать? - сейчас все кратко и останется только дергать сами алгоритмы стратегий каждый тик или реже