+ 10
Complex Class Problem - How to save data in the Complex Array?
I have a Complex Class, and I have added a Root() function to calculate nth roots... https://www.sololearn.com/discuss/314267/?ref=app Now, Instead of putting k and getting a root, I decided to pass a Complex Array and save the roots in it... That works... and printing the elements 'inside the function' shows all the correct roots... Complex array = Complex *z; Then did = z= new Complex[100]; And assigned the values in a for loop of k = for(k=0;k<n;k++) { z[k]=Complex(real_pt,imag_pt); } Now,the problem
4 Respuestas
+ 12
Please Help!
+ 11
Is that, on calling the function with an actual argument, the values in it are unchanged!
How to ensure that the changes are reflected here as well?
Isn't a pointer/array passed by reference?
//Of course it is, it is memory itself...
Then why is it happening?
Please help!
+ 11
Also, If I make the function return the pointer array instead, the values are altered...
But why are they the same if I pass the pointer as an argument?
+ 11
@JPM7
But why does it work with returning?
And secondly, Isn't a vector nothing but a class containing pointer memory altered using new and delete?