C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 16th, 2012, 02:59 PM
Xerian Xerian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 Xerian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}

Reply With Quote
  #2  
Old November 17th, 2012, 04:04 PM
Xerian Xerian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 Xerian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m
Reputation Power: 0
Sigh... it is always something that makes you feel stupid

In the private declaration of class Car I had () at the end of isIgnitionOn which caused the error.

Well thanks to anyone who thought about it none the less

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ modifiable lvalue error


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap