'<' - template mismatch

 

Hello How are you?


A little help please

I would like to work with the Carray class, but I find it penalizing that I can’t do a printarray on the array manipulated by the class.

So I wanted to make a template function that would have allowed me to do the arrayprint Here is the code

template <typename T>
void PrintArray (CArray<T> &array)
   {
      // Obtenir la taille du tableau
      int size = array.Total ();
      
      // Créer un tableau temporaire
      T array_tmp [];
      
      // Redimensionner le tableau temporaire avec la taille du tableau de la classe
      ArrayResize (array_tmp, size);
      
      // Parcourir le tableau avec une boucle for
      for (int i = 0; i < size; i++)
      {
          // Obtenir l'élément à l'index i avec la méthode At
          T element = array.At (i);
         
          // Ajouter l'élément au tableau temporaire
          array_tmp [i] = element;
      }
      
      // Imprimer le tableau temporaire dans le journal avec la fonction ArrayPrint
      ArrayPrint (array_tmp);
   } 

My problem is that I can’t write the declaration of the function

void PrintArray (CArray<T> &array) 

‘<’ - template mismatch

If you can help me with the syntax, or maybe a different solution to have the ArrayPrint of the class?

Thank you

Documentation on MQL5: Standard Library / Data Collections / CArray
Documentation on MQL5: Standard Library / Data Collections / CArray
  • www.mql5.com
CArray - Data Collections - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
William210:

Hello How are you?


A little help please

I would like to work with the Carray class, but I find it penalizing that I can’t do a printarray on the array manipulated by the class.

So I wanted to make a template function that would have allowed me to do the arrayprint Here is the code

My problem is that I can’t write the declaration of the function

If you can help me with the syntax, or maybe a different solution to have the ArrayPrint of the class?

Thank you

Depends on how you call the function

This signature will only work, if you specify the type correctly, like you did at creating the CArray object

void PrintArray (CArray<T> &array)

You need to call it like this:

CArray<int> my_obj();

PrintArray<int>(my_obj);

Alternative you could do this:

void PrintArray (T &array)

And then call it like this:

PrintArray(array);

 
Thanks a lot