Learning and writing together in MQL5 - page 33

 

We need to move initialization to the initialization list.

Only static integral constants can be initialised in the declaration (at least in C++, I don't know yet in MQL5 :) )

 
One more question, the last one. What is the reason that "" and NULL for strings are not equivalent?
 
Interesting:

Speaking of birds.

And what will the compiler answer to this? And it will answer the following '=' - illegal assignment use

The compiler was unbowed - '=' - illegal assignment use.

I have a question. What will happen if the programmer (in this case, me) doesn't initialize variables before using them (he/she does what the compiler requires and omits this moment in the constructor)?


The right way to initialize members of structures/classes in the constructor(s):

//Struct StrMQL4_Deal
struct StrMQL4_Deal
{
//----------------------------------------------------------------------------//
double TP;
double SL;
//----------------------------------------------------------------------------//
StrMQL4_Deal():TP(0),SL(0) { }
StrMQL4_Deal(double  tp,double  sl):TP(tp),SL(sl) { }
};
 
TheXpert:
One more question, the last one. What is the reason that "" and NULL for strings are not equivalent?
NULL means the string is unallocated and "" the string is allocated and has a value.
 
mql5:

properly initialise structure/class members in the constructor(s):

Yes I realised this over a year ago, at least since 2010 I have been doing so.
 
Interesting:
Yeah I figured that out over a year ago, at least since 2010 I've been doing it that way.

You could not have done it correctly since 2010, because the initialisation list was introduced quite recently :) .

mql5:

NULL means the string is unallocated and "" the string is allocated and has a value.

OK, I'll put it another way. What's the point of inputting "not distributed" string state to the user? Can it be used in some useful way or is it just a crutch?
 
TheXpert:
You couldn't have done it right since 2010, as the initialisation list was only recently introduced :) .
meant in the constructor.
 
TheXpert:

You couldn't have done it right since 2010, as the initialisation list was introduced quite recently :) .


I meant initialization in class constructor and declaration as

//----------------------------------------------------------------------------//
double TP;
double SL;
//----------------------------------------------------------------------------//
I don't remember exactly, but I started working with objects at the beginning of 2010 (first quarter, I can't say exactly; and it's tedious to look for sources). Before that I was dealing with libraries and studying the basics of MQL5 (or rather, dealt with MQL5 migration issues).
 
Rosh:
Do an overload function on different types of data in the array.
Oops, got it. So, there is no universal way. The question arose because overloading results in identical functions with only one(!) difference - in the function header, when you have to specify an array type. Not exactly neat, but what can I do, I'll leave it that way. Was hoping there was a way out, like in the Reference Manual.
 

A simple script like this gives me strange results

void OnStart()
  {
   for(uchar u=120;u<136;u++)
     {
       switch(u>254)
        {
          case  true: Print(u,">254 - true");  break;
          case false: Print(u,">254 - false"); break;
        }
     }
  }

Maybe someone can explain what's the reason? When number 254 is explicitly converted to uchar, it works as intended.