我的正 double 值打印为负输出,如 -6.27744e+66

My positive double value is printed as a negative output like -6.27744e+66

我得到一个正双变量的负输出。 我的对象是:Fahrzeug fr("BMW",200.45);

 class Fahrzeug {
    private:
    string p_sName;
        double p_dMaxGeschwindigkeit;
    public:
        Fahrzeug(string p_sName, double p_dMaxgeschwindigkeit) {
            this->p_sName = p_sName; 
            this->p_dMaxGeschwindigkeit = p_dMaxGeschwindigkeit; //the output is negative
            cout << "Der Name des Fahrzeugs: " << this->p_sName << "\n" << "Die maximale Geschwindigkeit des Fahrzeugs: " << this->p_dMaxGeschwindigkeit << endl;
            }
    };
        #endif /* FAHRZEUG_H_*/

this->p_dMaxGeschwindigkeit = p_dMaxGeschwindigkeit; 这会将(未初始化的)成员变量分配给它自己。

您还有一个名为 p_dMaxgeschwindigkeit 的参数,您可能打算使用它,但请注意它的拼写不同 - 它有一个小写字母 G 而 C++ 区分大小写。