problem in initializing an array
Dec 9, 2012 at 3:01pm UTC
I tried to initialize an array in the constructor of my class. here is how it looks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
MyClass::MyClass(double **arr, int N,int d)
{
firstd=N;
secd=d;
arr=new double *[firstd];
for (int i=0;i<firstd;i++)
{
arr[i]=new double [secd];
}
for (int i=0;i<N;i++)
{
for (int j=0;j<d;j++)
{
arr[i][j]=0;
}
}
}
but when I try to use it in main function like below code:
1 2 3
double **myarr;
int N=5,d=4,i;
MyClass ıhopeitworks(myarr,N,d);
It gives a run time error and says that myarr is not initialized
and I can't understand the problem, what is wrong ??
Last edited on Dec 9, 2012 at 3:02pm UTC
Dec 9, 2012 at 3:07pm UTC
I think its because **myarr does not hold a value. You need to set it to something (maybe). I am a noob to pointers but that is usually what that error means.
Dec 9, 2012 at 3:27pm UTC
but I did set it to zero in the consructor
Topic archived. No new replies allowed.