我在头文件中有一个这样的类声明:
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);
}
}
在添加之前只有错误,我已经尝试在复杂的函数调用者之前放置东西,但它仍然说在添加之前它会有所期待......有人可以帮忙吗?
答案 0 :(得分:1)
此功能
void COMPLEX :: complex add(complex n, complex m, int form)
看起来正在返回void
和COMPLEX::complex
。
你必须决定你想要它返回什么。