Have also tried a class rather than a structure and that doesn't work either:
Code:
#include <Arrays/ArrayObj.mqh> class CTest : protected CObject { private: double a; double b; datetime c; public: void setA(const double value) { a = value; }; void setB(const double value) { b = value; }; void setC(const datetime value) { c = value; }; double getA() { return a; }; }; CArrayObj *obj = new CArrayObj; void OnStart() { //--- CTest tc; tc.setA(1.0); tc.setB(2.0); tc.setC(iTime(NULL,0,0)); obj.Add(tc); const test_t r = obj.At(0); PrintFormat("obj[0].a = %f", r.getA()); delete obj; }
Errors:
lippmaje:
It works only with objects derived from CObject. And that means classes only.
or
Ok, thanks very much.
This should work (untested):
CTest tc; tc.setA(1.0); tc.setB(2.0); tc.setC(iTime(NULL,0,0)); obj.Add(&tc); CTest *r = obj.At(0); PrintFormat("obj[0].a = %f", r.getA());
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
Hello,
I'm trying to add a series of structures to a CArrayObj but having problems. Could someone point me to the solution please?
My code is as follows:
and I'm receiving these compilation errors:
Seems to be a conversion type of problem but I've tried casting to both test_t and CObject with no success. Help please?
Thanks.