#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() { } }; //+------------------------------------------------------------------+
Amir Yacoby:
Thank you very much Amir.
rob:
Thank you very much Amir.
Struggling here. How do I instantiate a new variable of type trendHistObj?
trendHistObj *tho = new trendHistObj<T>();
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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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?