How to template a CList to filter out non CObjects

I want to check when I put/pull out a derived CObject from a derived Clist that it is of the correct type:

I thought templating somehow but I can’t find a reference to it?

#include <Arrays\List.mqh>
//+------------------------------------------------------------------+
//| List of trendElements                                            |
//+------------------------------------------------------------------+
class trendHistObj : public CList <template trendHistElement>
  {
public:
   void trendHistObj()
     {

     }
                    ~trendHistObj()
     {
      //remove  and delete trendHistElements
      Clear();
     }
  };
//+------------------------------------------------------------------+
//| trendHistElement                                                 |
//+------------------------------------------------------------------+
class  trendHistElement : public CObject
  {
public:
   string            state;
                     trendHistElement(string _state)
     {
      state=_state;
     }
                    ~trendHistElement()
     {

     }
  };
//+------------------------------------------------------------------+
#include <Arrays\List.mqh>
//+------------------------------------------------------------------+
//| List of trendElements                                            |
//+------------------------------------------------------------------+
template<typename T>
class trendHistObj  : public CList<trendHistElement *>
  {
public:
   string            state;
   trendHistObj(string _state)
     {
      state=_state;
     }
                    ~trendHistObj()
     {

     }
  };
//+------------------------------------------------------------------+
//| trendHistElement                                                 |
//+------------------------------------------------------------------+
class  trendHistElement : public CObject
  {
public:
   string            state;
                     trendHistElement(string _state)
     {
      state=_state;
     }
                    ~trendHistElement()
     {

     }
  };
//+------------------------------------------------------------------+

Struggling here. How do I instantiate a new variable of type trendHistObj?

trendHistObj *tho = new trendHistObj();

CList is very slow compared to CArrayObj because the latter uses a contiguous array under the hood. So unless you’re inserting objects in random places or using the collection as a double ended queue then you should use CArrayObj instead. This is a common recipe that I resort to…

#include <arrays/arrayobj.mqh>
template <typename T>
class ObjVector : public CArrayObj {
   public: T operator[](int i){ return this.At(i); }
};
void OnTick() {

   // better way to declare the vector
   ObjVector<CObject*> arr1;
   arr1.Add(new CObject());
   
   // only declare array as a dynamic object if you absolutely have to!
   ObjVector<CObject*> *arr2 = new ObjVector<CObject*>();  
   
   // vector of vectors
   ObjVector<ObjVector<CObject*>*> matrix; 
}

Got it … thankyou … I will attempt to ammend my code accordingly