I have a class declared like this in a header file :
class COMPLEX{
private:
typedef struct{
double real;
double imaginary;
}complex;
Now when I call this from the function driver I get that error “expected initalizer before add right here in this section of code, and as you can see I have it just like other parts that compile just fine.
//returns the phase of the complex number
double COMPLEX :: getPhase(complex n, int form)
{
if(form == 0)
{
float x = n.real;
float y = n.imaginary;
return(atan2(y,x));
}
if(form == 1)
{
return(n.imaginary);
}
}
//adds two complex numbers together
void COMPLEX :: complex add(complex n, complex m, int form)
{
complex temp, temp2, temp3;
if(form == 0)
{
temp.real = n.real + m.real;
temp.imaginary = n.imaginary + m.imaginary;
return(temp);
}
if(form == 1)
{
temp3.real = (n.real*cos(n.imaginary) + m.real*cos(m.imaginary));
temp3.imaginary = (n.real*sin(n.imaginary) + m.real*sin(m.imaginary));
temp2.real = getMagnitude(temp3, 0);
temp2.imaginary = getPhase(temp3, 0);
return(temp2);
}
}
There is just the error right before add, I’ve tried putting things before the complex function caller but it still said it was expecting something before add…. can anyone help?
This function
looks like it is returning both
voidandCOMPLEX::complex.You have to decide what you want it to return.