[英]Why do I keep getting the error: "undefined reference to 'robots::robots()'
[英]Why do I keep getting error message like 'undefined error'?
我正在尝试使用以下代码计算 BMI,但我不断收到错误消息,例如未定义错误并返回 1 退出状态。 我在某处读到我需要包含一个带有 .h 的文件,所以我添加了<windows.h>
,但它仍然不起作用。
我对课程不熟悉。
我该如何解决?
#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;
}
您声明了一个析构函数~BMI()
,但没有定义它。 只需删除声明。 你不需要析构函数。 没有什么可以破坏的。
还有其他问题。 阅读所有警告并采取行动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.