Print_CArrObj template - better use (if I'm not mistaken)

 

well I don't know Why,

but after getting acquainted with this topic & some of my tests, that I will not reproduce now, - I found that such code ONLY

template<typename T, typename U, typename T0>
void PrintArrObj(const T &arrobj0)
  {
   T arrobj= (T) arrobj0;
   int sz=arrobj.Total();
   int i=0;
   while(i<sz)
     {
      if(CheckPointer(arrobj)!=POINTER_INVALID)
        {
         U e = (U) arrobj.At(i);   // to see bad pointer in Locals...

         if(CheckPointer(e)!=POINTER_INVALID)
           {
            T0 ee= dynamic_cast<T0>(e);
            Print(i, " >> ", ee.ToString());   // ToString()should be defined in eMyClass... 
           }
         //else Print("bad pointer");
        }
      i++;
     }
  }

with such use

PrintArrObj<arrMyClass*,CObject*, eMyClass*>(arrTest);

- shows IF bad pointer occurs...

- the pointer is equal to NULL;

- the object has been deleted using the delete operator.

and if refactor this code for such signature

PrintArrObj<arrMyClass*, eMyClass*>(arrTest);

without CObject* use - it always only throws error "invalid pointer access" (& need some efforts to identify where exactly)... though arrMyClass was inherited from CArrayObject... but only using CObject* as intermediary - in LocalWindow "bad pointer" is seen!... otherwise not.

I don't know why yet, but will prefer to use such a form of checking errors in Debug & Experts_sheet... while will not find more neat way to see bad pointers in CArrayObj in Debug (without just throwing errors)

P.S.

perhaps GetPointer from "this" will be needed if used in class - though

It's also prohibited to pass the pointer as a function argument.

and keyword "this" e.g. in C++ has a pointer-like-nature... but in MQL - pointer is just a handler (descriptor of object)
Invalid Pointer Access - Distilled ...
Invalid Pointer Access - Distilled ...
  • 2017.12.01
  • www.mql5.com
My earlier similar titled post refers. I've distilled the issue down to the following:- I create the sortPivotCandidates object in the method...