Features of the mql5 language, subtleties and tricks - page 193

 
fxsaber:

Absolutely all the rules are artificial.

I agree. The question is the level of art :)

 

Please advise - if you use a custom indicator that has a lot (say, 50) parameters, what are the best ways to manage the indicator parameters? (except direct transfer of parameters of an indicator to expert pairs, everything is clear here)

I have found the use of *.set file loading in somebody else's code when calling iCustom, but I haven't found anything of that kind and it looks like it doesn't work in the test.

Maybe someone knows and there are some undocumented tricks?

 

The latest release build is 2650. It's ok for a script like this not to compile:

struct A_INFO
{
  int a;
};

bool operator<(const A_INFO &First,const A_INFO &Second) //operator< has invalid parameters count
{
  return First.a<Second.a;
}

void OnStart()
{
}

And this is normal:

struct A_INFO
{
  int a;
};

bool operator<(const A_INFO &First)
{
  return true;
}

void OnStart()
{
}

Is it expecting me to compare 1 value? Or why can't the operator be made a non-memberstructure?

 
And a second follow-up question. Why can't ArraySort be applied to an array of such structures? What prevents them from being compared using the < operator, which is defined?
 
traveller00:

It expects me to compare 1 value?

The second value (that to the left of the operator) is this.

 
fxsaber:

The second value (the one to the left of the operator) is this.

Why this if I didn't make the operator a member of the structure, but globally? Or can't I make it global? C++ behaves differently.

 
traveller00:

Why this, if I made the statement globally rather than as a member of a structure? Or can't I do it globally? C++ behaves differently.

I don't know anything about such operators.

 
traveller00:
And the second question I have on the follow-up. Why cannot ArraySort be applied to an array of such structures? What prevents them from comparing through the operator < which is defined?

The built-in ArraySort is just a function, overloaded for all standard types.

Classes and other OOP are a help. If all types (structures) had a common ancestor(CObject in SB) and so on...

 
Aleksey Mavrin:

The built-in ArraySort is just a function, overloaded for all standard types.

Classes and other OOP are a help. If all types (structures) had a common ancestor (CObject in SB) and so on...

Yes, I have an approximate idea of how it is done inside. The question was rather not for an answer. But as a suggestion to pay attention to other variants of implementation, e.g. STL, and to handle containers in a similar way, where we can write universal things, including sorters.

 
traveller00:

I have a rough idea of how it's done on the inside. The question wasn't for the sake of an answer. But as a suggestion to pay attention to other variants of implementation, for example STL, and to do similar way of work with containers, where we can write universal things, including sorters.

No doubt, STL for sure) While ArraySort can be overloaded by making it template-based and then using it, but I'm not a specialist in templates, I'm used to working with simple class hierarchies.