Errors, bugs, questions - page 2364

 
Igor Makanu:

it is all clear, and it is not a small difference, I will say that the code of professional programmer differs from amateur one exactly in this difference - in check of critical errors ..... Although with modern trends in programming languages it has simplified for lamer programmers usingtry except finally and so on ;)

Actually Try/Catch is a more interesting topic than it may seem:) Too bad it's not in MQL.

 
And it's not at all clear how it can be beautifully implemented by your own means.
 

Who can tell me what it's fighting about and what to do about it?

#property strict

template<typename T> struct A
 {
  A<T> f();
  
  int i;
  
  static int k;
 };

//---

template<typename T> int A::k=0;

//---

void OnStart()
{
  A<int> a;
}

//---

template<typename T> A<T> A::f()
 { 
  A<T> r; 
  r.i=0; 
  return r; 
 }


 
Vasiliy Sokolov:

Imho, MQL is more like a very stripped down C# with complete lack of syntax sugar.

Ok, I've never had any desire or opportunity to play around with C#, I've opened VS2017 a couple of times, at C++ level and tried to write in Delphi, so far I haven't understood it - I will definitely take a closer look at C# now


Ilya Malev:

Who can tell me what it frowns on and what to do about it?

I don't know if it helps you, but in MQL the structures are not exactly the same as classes, as Vasiliy mentioned above, MQL is a bit like C# - there they create static memory structures, and classes are kind of in the heap

I was looking for a solution through the description of the structure, but was told to "wrap" it in classeshttps://www.mql5.com/ru/forum/6343/page866#comment_7541747.

maybe your example will work in a class?

Вопросы от начинающих MQL5 MT5 MetaTrader 5
Вопросы от начинающих MQL5 MT5 MetaTrader 5
  • 2018.05.23
  • www.mql5.com
Подскажите пожалуйста, такой показатель тестера в жизни реален? И хороший это или плохой результат за год с депо 3000...
 
Igor Makanu:

would your example work in class?

No, it doesn't depend on that. This is a mating dance of templates with statics.

 

Service desk pay attention to the application

Open,Started: 2018.12.17 14:19,#2224434

 
Comments not related to this topic have been moved to "Questions from MQL4 MT4 MetaTrader 4 beginners".
 
Ilya Malev:

Who can tell me what it's fighting about and what to do about it?

Write the body of the method inside the class.

 
fxsaber:

Write a method body inside a class.

How to make it work, I've already figured it out myself. The question is about the reasons for the error, why you can't write it the way it is written, in terms of logic and common sense

 
Ilya Malev:

I've already figured out how to make it work myself. The question is about the reasons for the error, why it cannot be written exactly the way it is written, in terms of logic and common sense

By the way, it's not the only error. The compiler also does not allow you to address the static field k with A<T>::k

Reason: