Download MetaTrader 5

How to set Multi-Type array

To add comments, please log in or register
selnomeria
254
selnomeria  

This topic is different from my previous topic...

for example, i want to have a function, which should set a bunch of different variables/values. Then I want to call that function , like this:

xxxx MyArrayContainter;

void OnInit(){
MyArrayContainter = MyFunc();
int a= MyArrayContainter.MyPipSize;
        string b= MyArrayContainter.SosName;
}


xxxx MyFunc(){
MyPipSize = XYZ;
SosName = XYZ;
return {int MyPipSizestring, string SosName};
}

Is anything like this, possible?

honest_knave
Moderator
2342
honest_knave  

You can't do this:

return {int MyPipSizestring, string SosName};

However, you can pass variables by reference and modify them directly from within the function.

You also might want to look into the use of structures if you want multi-type arrays.

whroeder1
17127
whroeder1  
selnomeria: Is anything like this, possible?
You can not return complex types.
//
xxxx MyArrayContainter;

void OnInit(){
MyArrayContainter = MyFunc();
int a= MyArrayContainter.MyPipSize;
        string b= MyArrayContainter.SosName;
}

xxxx MyFunc(){
MyPipSize = XYZ;
SosName = XYZ;
return {int MyPipSizestring, string SosName};
}
struct Values{ int MyPipSize; string SosName; }
Values MyArrayContainter;

void OnInit(){
   MyFunc(MyArrayContainter);
   int    a= MyArrayContainter.MyPipSize;
   string b= MyArrayContainter.SosName;
}

void MyFunc(Values& container){
container.MyPipSize = XYZ;
container.SosName   = XYZ;
return;
}
selnomeria
254
selnomeria  
whroeder1:
You can not return complex types.

Wow, thanks!
To add comments, please log in or register