得到神秘的非类型错误(必须简单)

时间:2017-03-13 09:59:09

标签: c++

对,所以我得到了另一个令我困惑的错误...我想要做的是添加两个复数的实部和虚部,我在调用disp()时得到错误信息。< / p>

主要罚款:

   #include <iostream>
#include "imaginary.h"


using namespace std;

int main()
{
int ImNum,ReNum,ImNum2,ReNum2;


cout<<"please provide the FIRST Imaginary number: ";
cin>>ImNum;
cout<<"please provide the SECOND Imaginary number: ";
cin>>ImNum2;
cout<<"please provide the FIRST Real number: ";
cin>>ReNum;
cout<<"please provide the SECOND Real number: ";
cin>>ReNum2;

imaginary addition(int ImNum, int ReNum, int ImNum2, int ReNum2);
addition.disp();
return 0;
}

构造函数文件:

#include<iostream>
#include "imaginary.h"

using namespace std;


imaginary::imaginary(int ImNum, int ReNum, int ImNum2, int ReNum2):
    Im(ImNum), Re(ReNum), Im2(ImNum2), Re2(ReNum2)
{
}

int imaginary::sumIm(){return (Im+Im2);}
int imaginary::sumRe(){return (Re+Re2);}
void imaginary::disp(){
    std::cout<< " The student named: ";
    }

我知道disp()没有显示我想要的内容但我稍后会修复。我得到的错误如下:

error: request for member 'disp' in 'addition', which is of non-class type 'imaginary(int, int, int, int)'

任何提示:

提前致谢:)

1 个答案:

答案 0 :(得分:2)

要调用构造函数,只需提及参数的名称。列表int ImNum, int ReNum ... 声明了参数,这反过来导致addition被声明为函数而不是变量。

你想:

imaginary addition(ImNum, ReNum, ImNum2, ReNum2);