how to pass complex number array to a function

Hi guys,

I am a beginner and have a problem now, I have defined a complex number class which defined the complex numbers and operations (+,-,*,/), now I want to pass the complex number to a function, how do I do that? can I use a pointer?


could I claim complex<double>** b ( b is a 2D complex number array), and could I pass b to a function ?
for example

#include <complex>
main
{
complex<double>** b, complex<double>** a;
solver(b, a);
return;
}
solver ( complex<double>**b, complex<double>** a)
{
c=a+b;
return(c);
}

I hope I have made myself clear. any suggestions will be appreciated.
Thanks in advance.
You are being clear, I think. What is not clear to me is why you are asking this instead of testing it yourself. It takes only a minute to test as opposed to waiting for a Yes/No answer. So maybe you are even asking the wrong question? Are you having trouble with the above code? Error messages of any kind?

Summary: Don't ask this, just test! If it doesn't work, then post your current non-working code, post errors, then describe what you want.

Oh, and use code tags to present code, please. See http://cplusplus.com/articles/z13hAqkS/ .
Hi webJose,

Thanks a lot anyway. I did test a lot, and the error information confused me a lot. there are so many same errors that said the variables a and b are not identified. I claim
1d array like this
complex<double>* r = (double*)calloc(NNMAX, sizeof(double));
and 2d array like this

complex<double> ** b=NULL;
CrtArrayCP(&b,NNMAX,NBMAX);

void CrtArrayCP(complex<double>*** pt,int row, int column)
{
int i;
*pt = (double**)calloc(row, sizeof(double*));
if (*pt==NULL)
{
printf("Can¡¯t allocate memory!\n");
exit(1);
}

for (i=0; i<row; i++)
{
(*pt)[i] = (double*)calloc(column, sizeof(double));
if ((*pt)[i]==NULL)
{
printf("Can¡¯t allocate memory!\n");
exit(1);
}
}
}

and I try to pass the complex array to function like this

#include <complex>
main
{
complex<double>** b, complex<double>** a;
solver(b, a);
return;
}
solver ( complex<double>**b, complex<double>** a)
{
c=a+b;
return(c);
}

I am not sure now if there is something wrong during my allocations, because I can't read that information from the error code.
if I did it right with the allocations, I know I have to check other problems.

Thanks a lot and waiting for more suggestions.
Topic archived. No new replies allowed.