Return an array of known length from a function (that takes in an arrayusing pointers

Joined
Mar 2, 2012
Messages
1
Reaction score
0
I am taking a matrix of size NxN and turning it into a long array to evaluate the velocity at many points in a domain. What I want to do is update the velocity using iterations to propagate the boundary conditions into the domain. In order to do this, I want to write a class that has member functions. I want one of these functions to pass the old values of the velocity array into the function, and use a pointer to return an updated array. I've read a few books and many online forums, and no one has provided a satisfactory solution.

This is what I've tried:
FUNCTION:
double *myClass::ReturnNewArray(double OldArray[], int length)
{
double *NewArray[length];
NewArray[0] = OldArray[0];
NewArray[length] = OldArray[length];

for (int i = 1; i < length; i++)
{
NewArray = OldArray + 0.5*(OldArray[i-1] + OldArray[i+1]);
}

return NewArray;
}

IN THE MAIN CPP File:
double length = 10, Velocity[length];
MyClass *NewVelocity[length];

Velocity = NewVelocity.ReturnNewArray(Velocity, length);

__________________________________________________________________
Can someone PLEASE help me? I would like a fairly detailed explanation so that I can thoroughly understand.

Additionally, if someone could help me understand how to make a void function that I can call that will update the array, that would be great. Or will the function always need to return type double (where my velocity will be a double type)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top