'return' - illegal operation use

 

I'm using this code:

#include <Arrays\ArrayObj.mqh>

template<typename T>
class CVector : public CArrayObj
{
public:
   T operator[](const int index) const { return At(index); }
};

from the end of this article: https://www.mql5.com/en/forum/34637

But when I compile it I'm getting the error:

'return' - illegal operation use

The original code compiles ok and the only thing I've changed is the objvector text to CVector and I don't understand why? I've even tried inserting the code in a seperate file and including it but will no avail. Could this be a bug?

Any help appreciated.

c++ vector like array
c++ vector like array
  • 2014.07.25
  • www.mql5.com
Hi I'm working on a mql5 program and need arrays like std::vector of c++ for example in my c++ code i have something like this: how can i implement...
 
Show all relevant code.
 
lippmaje:
Show all relevant code.

The only other piece of code I'm using is this:

CVector<datetime> m_times;

And does seem to be the initialisation that is causing the problem. How should I be initialising this code?

Thanks.

 

As far as I could gather from the source code you need to use a class derived from CObject. So your best choice would be to define a datetime wrapper.

See how CString does it in String.mqh, you'd go something like this:

class CDatetime : public CObject
  {
protected:
   datetime          m_datetime;

public:
                     CDatetime(datetime dt=0);
                    ~CDatetime(void);
   ...
  }

CVector<CDatetime> m_times;


Another approach could be to use ArrayInt.mqh but you'd have to cast its elements into datetime here and there. This is no issue as datetime and int have the same size.

#include <Arrays\ArrayInt.mqh>

CArrayInt v;
 
lippmaje:

As far as I could gather from the source code you need to use a class derived from CObject. So your best choice would be to define a datetime wrapper.

See how CString does it in String.mqh, you'd go something like this:


Another approach could be to use ArrayInt.mqh but you'd have to cast its elements into datetime here and there. This is no issue as datetime and int have the same size.

Thanks