Download MetaTrader 5

pass a array reference to a function and assign it to a value

To add comments, please log in or register
Christian Stern
Christian Stern  

Hey all,

could please someone help me ? Guess i didn't got the concept completly.

I have a class which should handle my buffer data. I want to pass a array to this class and set the pointer to a internal variable.

Like this:

// add a object to list
class1 object = new class1;

// create a array

double arrayRef[];

// pass array

object.setArrayRef (arrayRef);

The class looks like this:

class class1 {
   void class1()  {};
   void ~class1() {};

   // var & functions
   double buffer[];       
   double setArrayRef (double &arrayRef[]);

double class1::setArrayRef (double &arrayRef[]) {
   my_buf.buffer = arrayRef;

When i do this, i get the error message:

'buffer' - invalid array access    array_struct_ref_simple.mq5   

Do i do something wrong or do i think on the wrong way ? Passing a array ref and work with the is fine, but this not.

My idea was like, setting once the pointer and having functions like getGreatestValue(), sortValues() etc ...which can work with the pointer.


Stanislav Korotky
Stanislav Korotky  
You can't do this in MQL. Instead you can wrap your buffer into an object and pass/assign a pointer to the object.
Christian Stern
Christian Stern  

yeah....thank you ! it works. Was a bit recoding but now it works like expected. I still have to get into the language.

Have a nice day !

To add comments, please log in or register