[英]Why do I keep getting error message like 'undefined error'?
I'm trying to calculate BMI with the code below, and I kept getting error messages like undefined error and return 1 exit status.我正在尝试使用以下代码计算 BMI,但我不断收到错误消息,例如未定义错误并返回 1 退出状态。 I've read somewhere that I need to include a file with .h, so I added
<windows.h>
, but it still doesn't work.我在某处读到我需要包含一个带有 .h 的文件,所以我添加了
<windows.h>
,但它仍然不起作用。
I'm not familiar with classes.我对课程不熟悉。
How can I fix it?我该如何解决?
#include <iostream>
using namespace std;
class BMI{
public:
void setWeight (int);
void setHeight (int);
int getWeight ();
int getHeight ();
int calBMI (int,int);
void printBMI (int);
BMI ();
~BMI ();
private:
double weight;
double height;
double bmi;
};
int BMI::getWeight(){
return weight;
}
int BMI::getHeight(){
return height;
}
void BMI::setWeight(int w){
weight = w;
}
void BMI::setHeight(int h){
height = h;
}
int BMI::calBMI(int w, int h){
return w/(h*h);
}
void BMI::printBMI(int ans){
cout<<ans<<endl;
}
BMI::BMI(){
weight = 0;
height = 0;
}
int main (){
int w, h, ans;
BMI body;
cout<<"\n\tPlease insert your weight = ";
cin>>w;
cout<<endl;
cout<<"\n\tPlease insert your height = ";
cin>>h;
body.setWeight(w); body.setHeight(h);
ans = body.calBMI(w,h);
body.printBMI(ans);
system ("pause");
return 0;
}
You declared a destructor ~BMI()
, but did not define it.您声明了一个析构函数
~BMI()
,但没有定义它。 Just remove the declaration.只需删除声明。 You don't need a destructor.
你不需要析构函数。 There's nothing to destruct.
没有什么可以破坏的。
There are other problems.还有其他问题。 Read all warnings and act on them.
阅读所有警告并采取行动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.