Ive been struggleing with the basic object oriented model given by MQL5 and is continuously keeps me showing its flaws and limitations.
This said, one of the major drawbacks to the OO model given by the MQL5 compiler is the restriction of not being able to return references.
Not only do I see no reason for it to have this limitation, it surely makes it very hard to find certain errors.
As an example, see following code:
Sab but its not possible to address or access the object within the array contained by the struct. It will give a copy of the object.
The operator would need following change, but thats not allowed by the compiler:
I would like to request this feature as it is very useful.
Any way to do this? Either request the feature or to work around this limitation?
mydata operator=(const int p_in) { val1 = p_in; return(this); }
Your code does not return a reference; it returns an actual mydata. use pointers:
mydata* operator=(const int p_in) { val1 = p_in; return &this; }
There are situations where pointers aren't ideal or possible. I wrote a container similar to C++'s vector class, lets say I write something like this:
array<int> numbers; numbers.push_back(1); numbers.push_back(2); numbers.push_back(3); // Won't update the first item since the operator can only return a copy. numbers[0] = 4;
Being able to return references will improve the language tremendously.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Ive been struggleing with the basic object oriented model given by MQL5 and is continuously keeps me showing its flaws and limitations.
This said, one of the major drawbacks to the OO model given by the MQL5 compiler is the restriction of not being able to return references.
Not only do I see no reason for it to have this limitation, it surely makes it very hard to find certain errors.
As an example, see following code:
Sab but its not possible to address or access the object within the array contained by the struct. It will give a copy of the object.
The operator would need following change, but thats not allowed by the compiler:
I would like to request this feature as it is very useful.
Any way to do this? Either request the feature or to work around this limitation?