我在头文件中有一个这样声明的类:
class COMPLEX{
private:
typedef struct{
double real;
double imaginary;
}complex;
现在,当我从函数驱动程序调用它时,我会在这段代码中的添加之前得到错误"预期的initalizer",正如你所看到的,我和其他编译得很好的部分一样
//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);
}
}
在添加之前有一个错误,我试着把东西放在复杂的函数调用程序之前,但它仍然说在添加之前需要一些东西。。。。有人能帮忙吗?
此函数
void COMPLEX :: complex add(complex n, complex m, int form)
看起来它同时返回CCD_ 1和CCD_。
你必须决定你希望它返回什么。