no, that '&' is not suppose to be there
The errors i'm getting are related to '<<' not '>>'...Quote:
Are you sure the problem with operator>> on tankstatus isn't that you are declaring two
outputs instead of one input and one output?
I'm not missing any semicolons, please check below..Code:
: error C2084: function 'std::ostream &operator <<(std::ostream &,Car::TankStatus)' already has a body
error C2264: 'operator <<' : error in function definition or declaration; function not called
different error..
TankStatus Car::getTankStatus()
{
return tankStatus;
}
syntax error : missing ';' before 'Car::getTankStatus'
Code:// Implementing function to return the name of current status
#include "car.h"
//#include "Menu.h"
using namespace std;
Car::Car() {};
std::string Car::getTankStatusName(TankStatus status)
{
switch (status)
{
case unknown:
return "unknown";
break;
case empty:
return "Empty";
break;
case half:
return "Half-Empty";
break;
case full:
return "Full";
break;
default:
throw std::runtime_error("Invalid tank status");
return "";
}
}
void Car::setCarDetails(string carMake, string carModel, unsigned yrModel,
unsigned engCap, TankStatus tnkStatus)
{
make = carMake;
model = carModel;
yearModel = yrModel;
engineCapacity = engCap;
tankStatus = tnkStatus;
}
// Operator < will be used by sort() function
bool Car::operator<(const Car& car) const
{
return make < car.make;
}
ostream& operator << (ostream& out, Car::TankStatus enumTStatus)
{
out << reinterpret_cast<int&>(enumTStatus);
return out;
}
istream& operator >> (istream& in, Car::TankStatus& enumTStatus)
{
int tStatus;
in >> tStatus;
enumTStatus = reinterpret_cast<Car::TankStatus&>(tStatus);
return in;
}
// Overload for reading input streams
istream& operator >> (istream& in, Car& car)
{
string make, model;
int ymodel, engCap;
Car::TankStatus ts;
in >> make >> model;
in >> ymodel;
in >> engCap;
in >> ts;
car.setCarDetails(make, model, ymodel, engCap, ts);
}
void Car::read(istream& indata, Car& car, bool isKeyboard)
{
Date dates;
indata >> car;
if(isKeyboard) {
readDates(dates);
}
}
void readDates(Date& dates)
{
int day, month, year;
cout << "\nEnter return dates [DAY - MONTH - YEAR]" << endl;
cin >> day;
cin >> month;
cin >> year;
dates.setTimeDate(day, month, year, 20, 59);
}
// Overload for enum variable when writing data
ostream& operator << (ostream& out, Car::TankStatus enumTStatus)
{
out << reinterpret_cast<int>(enumTStatus);
return out;
}
// Ouput the data to screen or file
void Car::write(ostream& out, bool isScreen, Date& date)
{
if(isScreen) // To the output screen
{
out << setw(6) << make << setw(8) << model;
out << setw(10) << yearModel;
out << setw(12) << engineCapacity;
out << setw(9) << date.getDay() << setw(3) << date.getMonth() << setw (5) << date.getYear();
out << setw(13) << getTankStatusName(getTankStatus()).c_str();
puts("");
}
else // To the file
{
out << " " << make << " " << model;
out << " " << yearModel;
out << " " << engineCapacity;
out << " " << date.getDay() << " " << date.getMonth() << " " << date.getYear();
out << " " << getTankStatus();
}
}
// Comparing the user entry with curent record
bool Car::sameModel(const std::string& car_model) const
{
return model == car_model;
}
string Car::getModel()
{
return model;
}
string Car::getMake()
{
return make;
}
unsigned Car::getEngineCap()
{
return engineCapacity;
}
unsigned Car::getYearModel()
{
return yearModel;
}
TankStatus Car::getTankStatus()
{
return tankStatus;
}