As I am using pointers member variables in my code , I had to create a dynamic memory allocation . But when i tried to delete the allocated memory space I, the compiler crashes and I have no idea ..why??
my code :
Class A{
private:
int max_abc;
B* p_xyz; //B is some other class type
C ** p_abc; //C is some other class type
public:
A(int max_xyz =2, int max_abc =2);
A(const A & Copy); //copy constructor
~A();
}
//and my constructor is as below
A::A (int max_abc )
{
p_abc= new C*[max_abc];
p_xyz= new B;
}
//copy constructor - I had to do deep copy
A:: A(const A & copy)
{
max_abc = copy.max_abc;
p_xyz= new B;
p_xyz= copy.p_xyz;
m_abc = new C*[max_abc];
for(int j=0;j<max_abc;j++)
{
m_abc [j] = new C;
m_abc [j] = copy.m_abc[j];
}
}
I seriously dont understand , why my compiler is crashed . Could some one please let me know, if my above definitions are correct\or reason for compiler crash ?? Please help....Thanks in advance!
XYZ::method_xyz has a default argument for its only argument so that if it is called without an argument, it will be as if it was called with the default argument.