我想知道是否有人可以在我尝试编译代码时了解这些错误消息的含义。这是我得到的错误:在函数'int main()'中:与'std :: operator 然后重复一会儿。我只想发布我的完整代码,这样您就可以知道我的任务是什么,时间不长! =)#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 tripsOdometer 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;} (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 您希望cout << void打印什么?totalfuel()返回void,并且您将其作为参数传递给cout::operator <<。您是要从该方法中返回某些内容吗?也许:double Odometer::totalfuel(){ fuel_efficiency = (milesDriven/gallonsUsed); return fuel_efficiency;} (adsbygoogle = window.adsbygoogle || []).push({}); 10-05 23:02