gpt4 book ai didi

c++ - 类(里程表)- 错误信息

转载 作者:太空宇宙 更新时间:2023-11-04 15:23:41 26 4
gpt4 key购买 nike

我想知道当我尝试编译我的代码时,是否有人可以给我一些线索,让我知道这些错误消息的含义。

这是我得到的错误:
在函数“int main()”中:不匹配 'operator<<'in 'std::operator<<[with_Traits = std::char_traits(((std::basic_ostr...

它会重复一段时间。

我想发布我的完整代码,这样您就可以了解我的任务是什么,不会那么长! =)

#include <iostream>
#include <cstdlib>
using namespace std;

class Odometer

{
public:

Odometer();

void reset();
void totalfuel();

void input_miles(int getmiles);
void Odometer::set_fuel_efficiency(double fuel_efficiency);

int gallonsUsed;

private:
int milesDriven;
double fuel_efficiency;
int getmiles;
};

Odometer::Odometer()
{
milesDriven = 0;
fuel_efficiency = 0;
}

void Odometer::reset()
{
milesDriven = 0;
}

void Odometer::totalfuel()
{
fuel_efficiency = (milesDriven/gallonsUsed);
}

void Odometer::input_miles(int miles_driven)
{
milesDriven = milesDriven + miles_driven;

}

void Odometer::set_fuel_efficiency(double Fuel_efficiency)
{
fuel_efficiency = Fuel_efficiency;
}

double Odometer::getgallons()
{
return milesDriven/fuel_efficiency;
}

// ======================
// main function
// ======================
int main()
{
// Two test trips
Odometer trip1, trip2;

trip1.reset();
trip1.set_fuel_efficiency(45);
trip1.input_miles(100);
cout << "For your fuel-efficient small car:" << endl;
cout << "After 100 miles, " << trip1.totalfuel() << " gallons used." << endl;
trip1.input_miles(50);
cout << "After another 50 miles, " << trip1.totalfuel() << " gallons used." << endl;

trip2.reset();
trip2.set_fuel_efficiency(13);
trip2.input_miles(100);
cout << "For your gas guzzler:" << endl;
cout << "After 100 miles, " << trip2.totalfuel() << " gallons used." << endl;
trip2.input_miles(50);
cout << "After another 50 miles, " << trip2.totalfuel() << " gallons used." << endl;

system("PAUSE");
return 0;
}

最佳答案

你会期待什么cout << void打印?

totalfuel()返回 void ,然后将其作为参数传递给 cout::operator << .您是要从方法中返回一些东西吗?

也许:

double Odometer::totalfuel()
{
fuel_efficiency = (milesDriven/gallonsUsed);
return fuel_efficiency;
}

关于c++ - 类(里程表)- 错误信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13753615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com