I have created a pointer to a data in a class A and passing this pointer to a function in another class B.when I try to delete this pointer in class A I get run time exception.
But if I dont delete the object of class B I dont get any error it runs fine.But I have to delete the object of class B.I have illustrated theexample..Cou ld anyone help with it?
[CODE=cpp]//func2.h
class b
{
private:
float * data2;
b(float *);
~b();
test2();
};
//func2.cpp
void b::b(float *_data2)
{
data2=_data2;
}
void b::~b()
{
if(data2!=NULL) { delete[] data2; data2=NULL; }
}
//func1.h
class a
{
private:
float *data1;
a();
~a();
test();
};
//func1.cpp
void a::a()
{
data1=NULL;
}
void a::~a()
{
if(data1!=NULL) { delete[] data1; data1=NULL; }
}
void a::test()
{
b *obj=NULL;
obj=new b(data1);
delete b;
b=NULL;
}[/CODE]
Thanks
But if I dont delete the object of class B I dont get any error it runs fine.But I have to delete the object of class B.I have illustrated theexample..Cou ld anyone help with it?
[CODE=cpp]//func2.h
class b
{
private:
float * data2;
b(float *);
~b();
test2();
};
//func2.cpp
void b::b(float *_data2)
{
data2=_data2;
}
void b::~b()
{
if(data2!=NULL) { delete[] data2; data2=NULL; }
}
//func1.h
class a
{
private:
float *data1;
a();
~a();
test();
};
//func1.cpp
void a::a()
{
data1=NULL;
}
void a::~a()
{
if(data1!=NULL) { delete[] data1; data1=NULL; }
}
void a::test()
{
b *obj=NULL;
obj=new b(data1);
delete b;
b=NULL;
}[/CODE]
Thanks
Comment