defining []= operator

 

Hi everyone,

I'm want to define []= operator in a class to change values of an array inside that class.

Is there anyway to return array's index by reference in mql5? If not, is there any way to define []= operator to change values of that array inside the class?

 
I'm not sure this is exactly what you're asking for, but take a look at this blog post.
 
Amir Shushtarian: Is there anyway to return array's index by reference in mql5? If not, is there any way to define []= operator to change values of that array inside the class?

Since MTx doesn't have pointers (only handles to classes,) it can't be done directly with POD.

If you have operator[] returning the internal array element, then no.

if you have operator[] return a helper class (containing pointer to the container class and the index) then the helper class can convert the assignment (*helper=value) to container.put(index,value). But then you can't do Print(container[x]) but instead Print(container.get(x))

IMO, it's not worth it. Just define container.put(index,value) and container.get(index) and be done.

 

Got it,

thanks