得到“complex-functions.cpp:57:25:错误:在'添加'之前预期的初始化程序”这是什么意思?

时间:2012-03-10 05:33:10

标签: c++ class typedef private complex-numbers

我在头文件中有一个这样的类声明:

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);
 }
}

在添加之前只有错误,我已经尝试在复杂的函数调用者之前放置东西,但它仍然说在添加之前它会有所期待......有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

此功能

void COMPLEX :: complex add(complex n, complex m, int form)

看起来正在返回voidCOMPLEX::complex

你必须决定你想要它返回什么。