I have a class with a dynamic array (DA)
class DA{
private:
double* array;
int size N;
//other stuff
public:
DA(){
array=NULL;
}
DA(int PN){
N=PN;
array=new double[N];
};
//destructor and other stuff
}
This seems to be ok. Now I want a class "Application" that has one DA object:
class App{
private:
DA myDA;
public:
App(int N){
//create myDA with array of size N
DA temp(N);
myDA=temp;
};
}
The problem is, that I don't know how to create myDA in the App constructor. The way I do it, memory is allocated for temp, then myDA points to temp. But I guess the memory allocated for temp is deleted after the constructor finishes. Hence, I get a memory error when I execute my program. So how do I allocate memory correctly?