'return' - illegal operation use

imamushroom
388

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...
lippmaje
1677
lippmaje  
Show all relevant code.
imamushroom
388
imamushroom  
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.

lippmaje
1677
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:

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;
imamushroom
388
imamushroom  
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