- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想知道当我尝试编译我的代码时,是否有人可以给我一些线索,让我知道这些错误消息的含义。
这是我得到的错误:
在函数“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/
我想实现一个 jQuery 里程表,类似于 opower.com 的网站。到目前为止,我能够让一些复制的代码正常工作,但是他们的里程表脚本周围有很多额外的代码,我复制的代码又臃肿又麻烦,而且有大量我不
我想知道当我尝试编译我的代码时,是否有人可以给我一些线索,让我知道这些错误消息的含义。 这是我得到的错误: 在函数“int main()”中:不匹配 'operator #include using
我想用 C# 风格的语言编写一个类似里程表的方法,但不只是使用 0-9 作为字符,而是使用任何字符集。它或多或少会像一个暴力应用程序。 如果我传入从 0 到 J 的字符数组,并将长度设置为 5,我想要
如何在 Delphi (Object Pascal) 中以如下方式实现以下算法: 每个字母数字项都是一个对象(在我的例子中是对文件字符串的引用)。 可以枚举(输出)每个选择状态/组合。 想象一下算盘的
我是一名优秀的程序员,十分优秀!