Access to dynamically created tables outside the if loop

advertisements

I have a scenario as follows

class A
{
double * array

void function1();

};

void A :: function1 ()
{
      if (condition)
      {
        array1= new double[n];
        fill the array1
      }

      **how to access the array1 here ?**
}


Define your array outside if

void A :: function1 ()

{
 float *array1= null;
if (condition) { array1= new double[n]; fill the array1 }
cout<<array1[0];

}