You have no At method. You have no pointers in your class. Don't post code that won't even compile.
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problem
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problem
William Roeder:
You have no At method. You have no pointers in your class. Don't post code that won't even compile.
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problem
You have no At method. You have no pointers in your class. Don't post code that won't even compile.
How To Ask Questions The Smart Way. 2004
Be precise and informative about your problem
Sorry, this is the code that fails:
#include <Arrays/ArrayObj.mqh> //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ class test_t : public CObject { public: double a; double b; datetime c; test_t(void) : a(0.0), b(0.0), c(0) {}; test_t(const test_t& src) : a(src.a), b(src.b), c(src.c) {}; }; CArrayObj *obj = new CArrayObj; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnStart() { //--- obj.Add(&build_struct(1.0,2.0,iTime(NULL,0,0))); const test_t *r = obj.At(0); if(r == NULL) PrintFormat(__FUNCTION__+", NULL"); PrintFormat("obj[0].a = %f", r.a); delete obj; } //+------------------------------------------------------------------+ test_t build_struct(const double a, const double b, const datetime c) { test_t t; t.a = a; t.b = b; t.c = c; return t; }
I think it is the build_struct function that is creating the problem. How can I correct it to function correctly?
imamushroom:
Sorry, this is the code that fails:
I think it is the build_struct function that is creating the problem. How can I correct it to function correctly?
Try this:
#include <Arrays/ArrayObj.mqh> class test_t : public CObject { public: double a; double b; datetime c; test_t(void) : a(0.0), b(0.0), c(0) {}; test_t(const test_t& src) : a(src.a), b(src.b), c(src.c) {}; }; CArrayObj *obj = new CArrayObj; void OnStart() { obj.Add(build_struct(1.0,2.0,iTime(NULL,0,0))); const test_t *r = obj.At(0); if(r == NULL) PrintFormat(__FUNCTION__+", NULL"); PrintFormat("obj[0].a = %f", r.a); delete obj; } //+------------------------------------------------------------------+ test_t* build_struct(const double a, const double b, const datetime c) { test_t *t=new test_t(); t.a = a; t.b = b; t.c = c; return t; }
That works, thanks.
Don't create an external build_struct — make a constructor.
test_t(const double aA=0, const double aB=0, const datetime aC=0) : a(aA), b(aB), c(aC) {}

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'm trying access a CObject* of a CArrayObj array but I can't seem to put it back into the structure that was originally placed there.
My complex type is:
And I'm accessing it with At like so.
It's when I access the CObject* in t,a that the indicator crashes so how do I convert it back to myobj_t. I've tried casting but that didn't work. Any help appreciated. Thanks.