Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1098

 
Grigori.S.B:

Please tell me why the compiler generates a warning in the following MQL4 test script code:

A warning on line 27 about data type mismatch. Both variables have the same int type. Below is a screenshot of the script compilation.

If I replace line 27 with

the warning doesn't show up.

What is the trick?

There is no trick. The variable t is declared as double

In fact, this t takes no meaning anywhere.

 
Alexey Viktorov:

And there is no trick. The variable t is declared as double

Thank you very much, I'm working hard - it's time to rest.

Alexey Viktorov:

In fact, this t doesn't take any value anywhere.

It's a buffer variable used to temporarily store the result during sorting.

 

How are these initialisation methods different?

class Klas{};
Klas *Klas_
Klas Klas_
 
Seric29:
1. class Klas{};
2. Klas *Klas_
3. Klas Klas_

1. type (class) description

2. declaration of type (class) pointer

3. declaration of class instance - this is initialisation, because Klas() constructor will be called if it's not described, then default constructor will be called - help

Seric29:

How are these initialisation methods different?

i.e. initialisation only step 3.

 
Igor Makanu:

1. type (class) description

2. declaration of type (class) pointer

3. declaration of class instance - this is initialization, because Klas() constructor will be called if it is not described, then the default constructor will be called - help

i.e. only clause 3 is initialized.

I haven't seen how to initialize them in the help, maybe I just watched it and didn't understand, since classes are poorly described in the help - I read it 30 times.

Yes, indeed after the class as I have no entries but they have put this code in OnStart

   CFoo foo1(TimeCurrent());     // явный вызов параметрического конструктора 
   CFoo foo2();                  // явный вызов параметрического конструктора с параметром по умолчанию 
   CFoo foo3=D'2009.09.09';      // неявный вызов параметрического конструктора 
   CFoo foo40(foo1);             // явный вызов конструктора копирования 
   CFoo foo41=foo1;              // неявный вызов конструктора копирования 
   CFoo foo5;                    // явный вызов конструктора по умолчанию (если конструктор по умолчанию отсутствует, 
                                 // то вызывается параметрический конструктор с параметром по умолчанию) 
//--- допустимые варианты получения указателей CFoo 
   CFoo *pfoo6=new CFoo();       // динамическое создание объекта и получение указателя на него 
   CFoo *pfoo7=new CFoo(TimeCurrent());// ещё один вариант динамического создания объекта 
   CFoo *pfoo8=GetPointer(foo1); // теперь pfoo8 указывает на объект foo1 

Understand it however you want. I don't know why I should explain it that way.

CFoo *pfoo6=new CFoo();       // динамическое создание объекта и получение указателя на него

I don't understand why I need this pointer.

CFoo *pfoo7=new CFoo(TimeCurrent());// ещё один вариант динамического создания объекта 

And what is this for? Whatever you want and what you think it means.

CFoo foo3=D'2009.09.09';      // неявный вызов параметрического конструктора

I also don't understand what this means.

CFoo foo40(foo1);             // явный вызов конструктора копирования 
What this is for is also not clear. They would not have uploaded it, but would have written down the idea normally and simply.
 

Greetings.

Could you please tell me how the horizontal levels for the grid are calculated in mt4 and in mt5?

 
Seric29:

And why initialize via pointer, I haven't seen it at all in help how to initialize them maybe I looked and didn't understand, because classes are poorly described in help read 30 times.

a pointer is a pointer, initialization is initialization

understand this code first:

1. int a;
2. int a = 5;

What is initialization in this code and what is a variable declaration?

When is memory being allocated?

and then treat the subject of OOP and pointers to a class and pointers to an object with this knowledge.


go away, for some reason I can't answer elementary questions

 
Igor Makanu:

a pointer is a pointer, an initialisation is an initialisation

understand this code first:

what in this code is initialization and what is variable declaration?

When is memory being allocated?

and then use this knowledge to discuss OOP and pointers to a class and pointers to an object.


gone, for some reason I can't answer elementary questions.

Here is a simple and clear example. 1st variant is declaration of variable and memory allocation(variable stores default rubbish arbitrary value or sector number or address in C++ here I don't know), 2nd variant is initialization.

And what these pointers to Type are for and what to eat them with should also have been explained normally.

Pointers to a class and pointers to an object

I should also have understood what they are. I will look it up on the net and see if there is something.

 
Andrey Sokolov:

Greetings.

How do you calculate horizontal levels for a grid in mt4 and in mt5?

If you want to detect a horizontal level, just open/close a new level and place a new order, or place a grid of pending orders taking into account the maximum number of orders and then display that grid.


there, in general, any compact code is easier to view and modify for your own tasks


I don't know if you have tried it and I've never tried a lot of programs and I think it's more difficult to use in simple TS, but maybe you have never tried it.

 
Seric29:

Here is a simple and clear example. 1st option is declaration of variable and memory allocation (variable stores default rubbish arbitrary value or sector number or address in C++ here do not know), 2nd option is initialization.

And why these pointers to Type and what to eat them with should also have been explained properly.

memory allocation will be in Example 1 and in Example 2

example 2 is a declaration and initialization, example 1 is only a declaration

the class is the same, the class is a user-defined type that contains fields (properties) and methods of working with these fields

a pointer to a class is a declaration, but without initialization and without memory allocation for the type (class)

pointer = new MyClass(); - this is a declaration and initialization, which creates a new instance of the class and this instance will be returned as a link to an object (not exactly a link, in MQL it's ... not important and so you get confused)

....

if you don't want to read it, at least use this post of mine to modify your example:

CFoo *pfoo6=new CFoo();

to

CFoo *pfoo6;
pfoo6 = new CFoo();
CFoo *pfoo_7 =  pfoo6;

and try to understand what happens - when you assign the last line to..... but still read, just asking on forums is not an option

Reason: