If you don't want to store copies, don't delete the original objects. Why are you delete 'tpB' and 'tpA' ? These are pointers to your original objects so of course after that you get NULL.
Those lines don't change anyhing.
You can comment them out and get the same results.
(I accidentally deleted my last reply, so posting it again)
Those lines don't change anyhing.
You can comment them out and get the same results.
(I accidentally deleted my last reply, so posting it again)
You are right and wrong. That's right you get the same results (invalid
pointer access) but it's wrong it "changes anything". Because there is an other problem, using the same object in 2
different CList doesn't work. When you add tpA or tpB to your Line (internal CList) it changes the state of the object (pointer prev/next),
which in turn changes the Pivots CList behaviour.
That means you HAVE TO USE a COPY, for your other list (CLine). That's not a bug but rather a limitation of CList due to a bad design. You have to deal
with it.
You are right and wrong. That's right you get the same results (invalid
pointer access) but it's wrong it "changes anything". Because there is an other problem, using the same object
in 2 different CList doesn't work. When you add tpA or tpB to your Line (internal CList) it changes the state of the object (pointer
prev/next), which in turn changes the Pivots CList behaviour.
That means you HAVE TO USE COPY, for your other list (CLine). That's not a bug but rather a limitation of CList due to a bad design. You
have to deal with it.
I see, its a bit weird. I guess I have some reading to do :)
Thanks a lot for the explanation.
You are right and wrong. That's right you get the same results (invalid pointer access) but it's wrong it "changes anything". Because there is an other problem, using the same object in 2 different CList doesn't work. When you add tpA or tpB to your Line (internal CList) it changes the state of the object (pointer prev/next), which in turn changes the Pivots CList behaviour.
That means you HAVE TO USE a COPY, for your other list (CLine). That's not a bug but rather a limitation of CList due to a bad design. You have to deal with it.
Great explanation. I had the same problem and didnt know that it's not possible to point from two different lists to the same object .
Thank you very much :)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am trying a fairly simple thing and failing miserably. Sorry for the long post but this got me scratching my head. Any explanation would be greatly appreciated.
My advisor is supposed to draw some trendlines.
I find some pivot points and store them in a CList called Pivots. No problem here.
But when I try to store those points as pairs in other CLists, the first CList starts to return "invalid pointer access" errors. (even though there is absolutely no tempering with the first CList, only GetNodeAtIndex calls)
When I investigate deeper, I find out that after the first for loop, GetNodeAtIndex returns null even though there should be something to return. (ie: GetNodeAtIndex(2) returns null on a CList with count of 6)
I worked around the issue by not storing the values of GetNodeAtIndex directly but rather storing their copies. But this doesn't make sense to me.
Should I not be using the values directly ever? Is this a memory mismanagement issue?
Am I doing something wrong here or is this a bug with CList?
Example code:
You can uncomment the parts that say (THIS WAY WORKS AS INTENDED) and comment out the (THIS DOESN'T WORK) parts to see it working. There are some prints to give an idea about whats going on.