I am looking for some help with the below code, I am trying to pass an object to a different class from a CArrayObj class using the At method which returns an object.
But so far everything I have tried gives a critical crash stating access to an invalid pointer. So how can I make this code work, what am I missing?
Thank you for your Time
EK
//+------------------------------------------------------------------+//| Test2.mq5 |//| Copyright 2010, MetaQuotes Software Corp. |//| http://www.mql5.com |//+------------------------------------------------------------------+#property copyright "Copyright 2010, MetaQuotes Software Corp."#property link "http://www.mql5.com"#property version "1.00"#property indicator_chart_window#include <Object.mqh>//#include <Arrays\ArrayObj.mgh>#include "C:\Program Files\MetaTrader 5\MQL5\Include\Arrays\ArrayObj.mqh"class A : public CObject
{
public:
string test_str;
int test_int;
float test_float;
// constructorvoid A() {test_str = "0"; test_int = 0; test_float = 0.0;}
// functionvoid Set_Values(A *nNew);
};
void A::Set_Values(A *nNew)
{
test_str = nNew.test_str;
}
class B
{
public:
A *MyA; // my instance of Cass A// constructorvoid B() { MyA = new A; }
//functionvoid Set_MyObject(A *NewObj);
};
void B::Set_MyObject(A *NewObj)
{
MyA.test_str = NewObj.test_str;
MyA.test_int = NewObj.test_int;
MyA.test_float = NewObj.test_float;
}
CArrayObj *MyListOfObjects;
B *ThisIsMyB;
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
int i;
// Create 10 new Objects of Class A and puts them in our ArrayObj Listfor(i = 0; i<10; i++)
{
A *Temp = new A;
MyListOfObjects.Add(Temp);
}
// now lets say I wanted to make one from my list and give it to Class B// ** but this gives invalid pointer access ***
ThisIsMyB.Set_MyObject(MyListOfObjects.At(7));
return(0);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime& time[],
constdouble& open[],
constdouble& high[],
constdouble& low[],
constdouble& close[],
constlong& tick_volume[],
constlong& volume[],
constint& spread[])
{
//---//--- return value of prev_calculated for next callreturn(rates_total);
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello Everyone,
I am looking for some help with the below code, I am trying to pass an object to a different class from a CArrayObj class using the At method which returns an object.
But so far everything I have tried gives a critical crash stating access to an invalid pointer. So how can I make this code work, what am I missing?
Thank you for your Time
EK