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

 

I want to create a one-dimensional array where 0 to 4 elements will store double, 5 to 9 will store datetame, 10 to 14 will store int. Is it possible to organize it in mql4? If so, could you show me how to do it? I saw an example with structures in C++, but I lost the link to the site?

 
Seric29:

I want to create a one-dimensional array where 0 to 4 elements will store double, 5 to 9 will store datetame, 10 to 14 will store int. Is it possible to organize it in mql4? If so, could you show me how to do it? I've seen an example with structures in C++, but I've lost the link to the site.

An array can only have one type.

But who forbids having an array type with a maximum data type? In this case it is double.

 
Artyom Trishkin:

An array can only have one type.

But who forbids to have an array type with a maximum data type? In this case - double.

I need the name to be the same, otherwise I'll have to do lefty checks. Can't I use a structure to declare variables in it and then combine them into an array? Can't you stick a union operator in the mix?

 
Seric29:

I need the name to be the same, otherwise I'll have to do lefty checks. Can't I do it through a structure, declare variables in it and then combine them into an array? Can't you glue a union operator to it?

The name of what?

 
Artyom Trishkin:

The name of what?

Array name. As I understand it is impossible, even if you make a structure, you will have to use a point and combine the information in one name, maybe I've seen the wrong one, I've lost the link.

 
Seric29:

Array name. As I understand it is impossible, even if you make a structure, you will have to use a point and combine the information in one name, maybe I saw the wrong one, I'm sorry I lost the link.

Why should we make different names for one array? How can you imagine?

So, you have one array to store various numeric types (except string, of course). The array must have a type equal to the maximum data type written into it. So, fill it with different types. And when you get them, watch out for indexes, which you already know, so that the right variables with the right types get values from different cells of the array.

From 0 to 4 elements will be stored double, from 5 to 9 will be stored datetame, from 10 to 14 will be stored int

double array[15];
array[0]=0.0; array[1]=0.1; array[2]=0.2; array[3]=0.3; array[4]=0.4;
array[5]=(datetime)5; array[6]=(datetime)6; array[7]=(datetime)7; array[8]=(datetime)8; array[9]=(datetime)9;
array[10]=(int)10; array[11]=(int)11; array[12]=(int)12; array[13]=(int)13; array[14]=(int)14;
One name:array
 
Artyom Trishkin:

Why make different names for the same array? How do you even imagine that?

So, you have one array to store different numeric types in it (except string, of course). The array must have a type equal to the maximum type of data written into it. So, fill it with different types. And when you get them, watch out for indexes, which you already know, so that the right variables with the right types get values from different cells of the array.

The name is the same: array

So they will store different data.

 
Seric29:

This is how different data will be stored in them.

What is "in them"?

 
Seric29:

I saw an example with structures but it was in C++ but I lost the link to the site?

if your example did not have pointers, then porting it to MQL will be no problem

Seric29:

Can't you glue union operator to the case?

union is not an operator! it's a type! it's described as a structure, but it's used to store different types of data in one memory spacehttps://www.mql5.com/ru/docs/basis/types/classes#union


Seric29:

I wanted to fix it, pass an array to macro and call overloaded function in macro and return the result. It seems to be primitive, but when I call overloaded function in macro, it warns that there are 3 functions, so I have to write in macro a criterion that will determine which of overloaded functions to call, but then I have to ask how to check this, in general, idea is lost.

start reading at least a book on C++, your questions are a blast, you write technical terms, at first glance it seems that you are asking a specific question, but in fact you just operate in terms without understanding the essence .... what will the macro return? where will it return? in the body of the macro reloadable function.... I can't even begin to explain what your question looks like.

To understand what a macro is, spell the term correctly, macroSUMMARY, maybe it will be easier for you to understand what it is

 
Seric29:

It should work like this.

In general, I want to achieve this effect, but I have no experience in the area of classes. The code compiles and works.

That's cool.

Reason: