Search code examples
c++mql5

Parameter conversion not allowed - MQL5 - CArrayObj


I have the following object declared in my global scope:

CArrayObj *UpwardMovements = new CArrayObj;

And I want to add CUpwards objects to UpwardMovements. CUpwards inherits from CObject so it is possible to add it to the array. However, I cannot add it to the array in a method.

For instance:

void OnTick()
{
   CUpwards *UpMovm = new CUpwards(ColorForUpwards);
   UpwardMovements.Clear();
   CalcUpwardMovement(UpMovm);
}



void CalcUpwardMovement(CUpwards &pUpMovm)
{
  UpwardMovements.Add(pUpMovm);
}

I get:

'pUpMovm' - parameter conversion not allowed

If I do the same in my OnTick() method, it works.

Any help would be greatly appreciated.


Solution

  • I solved the problem as follows:

    UpwardMovements.Add(GetPointer(pUpMovm));
    

    You may want to check the pointer before this operation with CheckPointer(GetPointer(pUpMovm));