简体   繁体   English

为什么我不断收到诸如“未定义错误”之类的错误消息?

[英]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.

相关问题 为什么我不断收到错误消息:“对&#39;robots :: robots()的未定义引用” - Why do I keep getting the error: "undefined reference to 'robots::robots()' 为什么我总是收到错误消息或构建错误消息? - WHy am I keep getting an error message or build error message? 为什么我不断收到此文件错误? - Why do I keep getting this file error? 为什么我在C ++中不断收到错误消息“在&#39;{&#39;标记之前不允许在这里进行功能定义”? - Why do I keep getting error message “a function-definition is not allowed here before '{' token” in C++? 为什么为什么不断收到错误消息“&#39;令牌&#39;&#39;”中没有名为“令牌类型”的成员? - Why do I keep getting the error message “no member named ”TokenType“ in 'Token' '”? 为什么我不断收到 Class 错误的重新定义? C++ - Why do I keep getting Redefinition of Class Error? C++ 为什么我不断重新定义类错误? - Why do I keep getting a redefinition of a class error? “在输入末尾预期&#39;}&#39;”。 为什么我不断收到此错误? - “Expected '}' at end of input”. Why do I keep getting this error? 为什么我在 VSCode 中使用 SFML 总是得到未定义的引用? - Why do I keep getting undefined reference using SFML in VSCode? 为什么我收到“标识符未定义”错误? - Why am I getting an “identifier undefined” error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM