Hi
This mql5 code is giving a run time error "invalid pointer access", Not sure why and how to fix it, please?
Thank you
Just like any array you have to resize it. This, of course, is best left handled to the object pointer collections CList and CArrayObj.
Just like any array you have to resize it. This, of course, is best left handled to the object pointer collections CList and CArrayObj.
I am sorry, I had to include more of the code wo show that the resize of the array is OK.
I am sorry, I had to include more of the code wo show that the resize of the array is OK.
Don't know what to tell ya... Most likely something is deleting the object or it losing its ref in the mix. I don't recommend working with pointers like that. Instead, take advantage of one of the collections I mentioned above.
#include <objvector.mqh> #include <Strings\String.mqh> void OnStart() { objvector<CString*> tests; for(int i=0; i<5; i++) { CString *s = new CString; s.Assign(string(i)); tests.Add(s); } for(int i=0; i<tests.Total(); i++) Print(tests[i].Str()); }
objvector is a subcass of CArrayObj
#include <Arrays\ArrayObj.mqh> template <typename T> //MUST BE OBJECT POINTER!!! class objvector : public CArrayObj { public: T operator[](const int i) const { return this.At(i); } bool Add(T element){ return CArrayObj::Add(element); } };
Hi
This mql5 code is giving a run time error "invalid pointer access", Not sure why and how to fix it, please?
Thank you
I was replying yesterday (mine) to your first topic, when you deleted it, to create this new one later. Please don't do that.
If the pointer is invalid, there is a reason, you need to debug your code. Nobody can help you with the snippet you posted, only possibility I see is the pointer was not initialized correctly at the start (lack of memory ?), or of course something like nicholishen said.
If you need help please post a code that compiles and reproduce your issue.
As suggested by nicholi
But errors 'see below';
compile time error in the file below:
include/objvector.mqh
#include <Arrays\ArrayObj.mqh> template <typename T> //MUST BE OBJECT POINTER!!! class objvector : public CArrayObj { public: T operator[](const int i) const { return this.At(i); } //<<< 'return'- type mismatch bool Add(T element){ return CArrayObj::Add(element); } //<<< 'element'-parameter conversion not allowed };
#include <objvector.mqh> objvector<News*> news; News *n = new News(country, title, t, impact, forecast); news.Add(n);
Any ideas on how to fix that last error pleaes?
Thank you
This mql5 code is giving a run time error "invalid pointer access", Not sure why and how to fix it, please?
class CLASS { public: int i; CLASS( const int Tmp ) : i(Tmp) {} }; void OnStart() { CLASS* Array[]; const int Size = ArrayResize(Array, 100); for (int i = 0; i < Size; i++) Array[i] = new CLASS(i); int Sum = 0; for (int i = 0; i < Size; i++) Sum += Array[i].i; Print(Sum); // 4950 - OK for (int i = 0; i < Size; i++) delete Array[i]; }
class News : public CObject { ... }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
This mql5 code is giving a run time error "invalid pointer access", Not sure why and how to fix it, please?
Thank you