I am having a problem copying a dynamically allocated array from one pointer to another. The error in my program comes after I enter the values of the dynamically allocated array and attempt to print them out. Any help would be greatly appreciated! Here is what I have so far:
void getVals(double *&dPtr)
{
double *d2Ptr;
cout << "Please enter the number of values you would like to be in your array!";
cin >> size;
d2Ptr = newdouble[size];
for(int i=0; i<size; i++) {
cout << "Please enter the value of array item #" << i+1 << ": ";
cin >> d2Ptr[i];
}
d2Ptr = dPtr; //<<==Problem with this statement
}
PS. If you are going to pass a reference to a pointer as a function parameter, then there is no need to create a separate pointer to hold the array and then assign this pointer to the reference pointer..
Which is a complicated way of saying that d2Ptr is not needed - just use dPtr
Okay, that is where I thought I was having the problem. However, I am unsure on how to fix it. Would I just need to copy the d2Ptr into dPtr using a for loop? If so, would it just be something like this?