You shouldn't use externally instantiated dynamic dependencies because it's going to halt your program the moment one of the gets destroyed. If you absolutely have to use this pattern then you need to take explicit ownership of the object in the class. The best way to implement this is to use one of the object collections that automatically delete the objects it points to when it gets destroyed.
#include <arrays/arrayobj.mqh> class Foo { CArrayObj m_objects; public: Foo(CArrayObj *objects) { // taking ownership of dependencies. the original collection cannot delete pointers objects.FreeMode(false); m_objects.AssignArray(objects); } ~Foo() { printf("Deleting %d objects from Foo", m_objects.Total()); } }; void OnStart() { CArrayObj arr; arr.Add(new CObject); arr.Add(new CObject); Foo foo(&arr); }
You shouldn't use externally instantiated dynamic dependencies because it's going to halt your program the moment one of the gets destroyed. If you absolutely have to use this pattern then you need to take explicit ownership of the object in the class. The best way to implement this is to use one of the object collections that automatically delete the objects it points to when it gets destroyed.
Thanks for your clarification...
I will need to change the way I do things.
- 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,
I'm a little confused trying to pass an array of pointers as a parameter of a class constructor.
and this is how I create a class in my code:
The program compiles but once executed it arise the following error: 2019.02.27 16:18:20.038 (EURUSD,M5) invalid pointer access in 'Controller.mqh' (102,17)
This line is: *pending = new MyClass( parFract, PENDING );
The fact is that I just need to pass references to the new class and I do not know what's wrong and how to accomplish it.
Does anyone could help me understand the concept of passing array of pointers?
Thanks in advance.