mdragganov:
I have a small custom class and I create an array from instances of that class.
I need to use a function that adds or updates the elements of that array and I get "Invalid pointer access error" when I call that function. The code is compilable but when started in the MT4 client gives that error.
Here is my code (MQL4, MetaEditor 5.00 Build 2375) {the line of the error has a comment just above it in method *add_new_pivot}:
Any ideas?
Hello
I just noticed that you have passed pointer of pp_ to the function because you have used the new keyword , when the function accepts not pointer for that object Pivot point you d cleared it to accept instance not pointer this might cause the issue try to modify the second argument of the function to accept pointer or simply don't use the new keyword I'm the declaration of pivot point
In other words your are mixing pointers with instances
Kareem Abdelhakim:
Hello
I just noticed that you have passed pointer of pp_ to the function because you have used the new keyword , when the function accepts not pointer for that object Pivot point you d cleared it to accept instance not pointer this might cause the issue try to modify the second argument of the function to accept pointer or simply don't use the new keyword I'm the declaration of pivot point
In other words your are mixing pointers with instances
void OnStart() { int index_ = iBars(_Symbol, _Period); double high_ = iHigh(_Symbol, _Period, 1); // increment #fork_counter fork_counter++; // create new fork PivotPoint PivotPoint *new_pp = new PivotPoint(index_, high_); // add the result add_new_pivot(fork_chain, new_pp, fork_counter); for(int i=0;i<ArraySize(fork_chain);i++) if(CheckPointer(fork_chain[i])==POINTER_DYNAMIC) delete fork_chain[i]; } void add_new_pivot(PivotPoint* &arr_pp[], PivotPoint *pp_, int counter) { ///<summary>Adds new #PivotPoint instance to a #PivotPoint /// _ list.</summary> // find array size int len = ArraySize(arr_pp); // when #counter is less than #len if(counter <= len) { ////----- Error "invalid pointer acces" on the next row (51)------- arr_pp[counter - 1]=pp_; Print(arr_pp[counter - 1].Index); // row 51 Print(arr_pp[counter - 1].PP); // row below gives the same error if used as na alternative to // _ the two lines above //arr_pp[counter - 1] = pp_; }
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 have a small custom class and I create an array from instances of that class.
I need to use a function that adds or updates the elements of that array and I get "Invalid pointer access error" when I call that function. The code is compilable but when started in the MT4 client gives that error.
Here is my code (MQL4, MetaEditor 5.00 Build 2375) {the line of the error has a comment just above it in method *add_new_pivot}:
Any ideas?