Download MetaTrader 5

Storing dynamic array reference which was passed through a function parameter

To add comments, please log in or register
gszabo
108
gszabo  

Hello,

does somebody know if it can be stored the value of a reference parameter which passes a dynamic array reference. Example:

class AAA
{
   ??? Buffer;

   void method_A(const double & buffer[])
   {
      Buffer = buffer;
   {

   double method_B(int idx)
   {
      return Buffer[idx];
   }
};

void Proc()
{
   AAA a = new AAA();
   
   a.method_A(Close);
   double x = a.method_B(20);
}

Thanks

Gabor

Ex Ovo Omnia
3294
Ex Ovo Omnia  
No, you cannot. What you can is defining the array inside an object and passing the object as a parameter. Just pay attention to its life cycle (its definition scope).
whroeder1
15582
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Mt4 doesn't have pointers to POD, only pointers to a classes.
    class Buffer{
     public:
       TYPE buffer[];
    }
    class AAA
    {
       Buffer* buffer;
    
       void method_A(/*const*/ Buffer& buffer)
       {
          buffer = GetPointer(buffer);
       {
    
       double method_B(int idx)
       {
          return buffer.buffer[idx];
       }
    };
    Also Don't use const, as constant upcast won't compile [(const TYPE*)p] and koenig lookup is broken.
gszabo
108
gszabo  
WHRoeder:

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Mt4 doesn't have pointers to POD, only pointers to a classes.Also Don't use const, as constant upcast won't compile [(const TYPE*)p] and koenig lookup is broken.

Thanks everybody, this is what I was afraid of. But with using struct I can't store the reference of Close, Open, High, ... or any of the indicator buffers.

Ex Ovo Omnia
3294
Ex Ovo Omnia  
gszabo:

Thanks everybody, this is what I was afraid of. But with using struct I can't store the reference of Close, Open, High, ... or any of the indicator buffers.

I believe it is possible, otherwise none of my indicators with buffers would work.
To add comments, please log in or register