
November 16th, 2012, 02:59 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 37 m
Reputation Power: 0
|
|
|
C++ modifiable lvalue error
I am following a book (Using C++ by Joyce Farrell) and using Microsoft Visual Studio 2010
and on this sample project, isIgnitionOn in the void Car::turnIgnitionOn() and turnIgnitionOff() functions are producing a modifiable lvalue error.
And being that I am a C++ noob and learning from the book I am not sure how to fix this error. I have matched my code with the code in the book and they are the same.
Any help is more than welcome and appreciated.
Code:
#include<iostream>
using namespace std;
class Car
{
private:
bool isIgnitionOn();
int speed;
public:
void turnIgnitionOn();
void turnIgnitionOff();
void setSpeed(int);
void showCar();
};
void Car::showCar()
{
if(isIgnitionOn)
cout << "Ignition is on. ";
else
cout << "Ignition is off. ";
cout << "Speed is " << speed << endl;
}
void Car::turnIgnitionOn()
{
isIgnitionOn = true;
}
void Car::turnIgnitionOff()
{
speed = 0;
isIgnitionOn = false;
}
void Car::setSpeed(int mph)
{
const int STD_LIMIT = 65;
if(isIgnitionOn)
if (mph <= STD_LIMIT)
speed = mph;
else
speed = STD_LIMIT;
else
cout << "Can't set speed - ignition is off!" << endl;
}
int main()
{
Car myCar;
myCar.turnIgnitionOn();
myCar.setSpeed(35);
myCar.showCar();
myCar.setSpeed(70);
myCar.turnIgnitionOff();
myCar.showCar();
return 0;
}
|