Declaration has no Storage

Declaration has no Storage

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 7261 Views - Last Post: 31 January 2010 - 02:23 AM Rate Topic: -----

#1 tarheelfan_08  Icon User is offline

  • D.I.C Regular

Reputation: -2
  • View blog
  • Posts: 256
  • Joined: 24-January 10

Declaration has no Storage

Post icon  Posted 28 January 2010 - 08:55 PM

When I run this program, my cout and cin are all showing up with red underlines. And the error is "Declaration has no Storage"! Can someone please help me get this going. What the program is trying to do us use a class and get the information about a car then print the information. I am new to classes and I may have messed up!


#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;

	//Class Declaration
	class Car
	{
		private:
			string make;  //make
			string	model; // model
			string	color;  // color 
			string liscensePlate;  // liscense plate number
			int	year;  // year
			int mileage;  // miles on car

		public:
			Car(); //constructor			
			string getMake;
			string getModel;
			string getColor;
			string getLiscensePlate;
			int getYear;
			int getMileage;
			void validation(int);
			void printCarDetails();
			void CarDetails ( string, string, string, string, int, int);

	};


	// Constructor to initialize each object to always start the same way
	Car::Car()
	{
		make = ""; 
		model = ""; 
		color = "";   
		liscensePlate = "";  
		year = 0;
		mileage = 0;
	}
	

	
	cout << "What is the car make? ";
	cin >> make;
	cout << "What the car model? ";
	cin >> model;
	cout << "What year is the car? ";
	cin >> year;
	cout << "What color is the car? ";
	cin >> color;
	cout << "What is the liscense plate number? ";
	cin >> liscensePlate;
	cout << "How many miles does the car have on it? ";
	cin >> mileage;
	while (mileage < 0 )
	{	
		cout << " This is not a valid mileage.\n";
		cout << " Enter the miles for this car: ";
		cin >> mileage;
	}

	cout << "The current car is a " << year << " " << color << " " << model << " with " << miles << " miles!  And the Liscense Plate number is " << liscensePlate << endl; 

	return 0;			




Is This A Good Question/Topic? 0
  • +

Replies To: Declaration has no Storage

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,879
  • Joined: 10-May 07

Re: Declaration has no Storage

Posted 28 January 2010 - 09:03 PM

Where is your main function?
Was This Post Helpful? 0
  • +
  • -

#3 tarheelfan_08  Icon User is offline

  • D.I.C Regular

Reputation: -2
  • View blog
  • Posts: 256
  • Joined: 24-January 10

Re: Declaration has no Storage

Posted 28 January 2010 - 09:04 PM

View Postno2pencil, on 28 Jan, 2010 - 08:03 PM, said:

Where is your main function?



I didnt think i needed one for classes. If so where will I put it?? After my class declaration or my constructor??
Was This Post Helpful? 0
  • +
  • -

#4 tarheelfan_08  Icon User is offline

  • D.I.C Regular

Reputation: -2
  • View blog
  • Posts: 256
  • Joined: 24-January 10

Re: Declaration has no Storage

Posted 28 January 2010 - 09:14 PM

And sorry by the way guys, I may be asking dumb questions or making dumb mistakes but I am new to this and just really beginning to learn!
Was This Post Helpful? 0
  • +
  • -

#5 tarheelfan_08  Icon User is offline

  • D.I.C Regular

Reputation: -2
  • View blog
  • Posts: 256
  • Joined: 24-January 10

Re: Declaration has no Storage

Posted 28 January 2010 - 10:02 PM

Anyone got any help for me??
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,879
  • Joined: 10-May 07

Re: Declaration has no Storage

Posted 28 January 2010 - 10:03 PM

Each time that you bump your topic, someone is less likely to help out. Just have some patience. This isn't a live 24x7 support forum. It's midnight on the US East coast, a lot of people are in bed as it's Thursday night.

I can't help any more as I don't know anything about classes in C++.
Was This Post Helpful? 0
  • +
  • -

#7 tarheelfan_08  Icon User is offline

  • D.I.C Regular

Reputation: -2
  • View blog
  • Posts: 256
  • Joined: 24-January 10

Re: Declaration has no Storage

Posted 28 January 2010 - 10:05 PM

View Postno2pencil, on 28 Jan, 2010 - 09:03 PM, said:

Each time that you bump your topic, someone is less likely to help out. Just have some patience. This isn't a live 24x7 support forum. It's midnight on the US East coast, a lot of people are in bed as it's Thursday night.



Sorry, i just get anxious! But what was it you was saying about the main?? I am not following you!
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,879
  • Joined: 10-May 07

Re: Declaration has no Storage

Posted 28 January 2010 - 10:07 PM

Every C/C++ project must have a main() function as it's the entry point to the program. What is your return 0 for if you have no function? What's it returning from, & to? You need main.
Was This Post Helpful? 0
  • +
  • -

#9 tarheelfan_08  Icon User is offline

  • D.I.C Regular

Reputation: -2
  • View blog
  • Posts: 256
  • Joined: 24-January 10

Re: Declaration has no Storage

Posted 28 January 2010 - 10:10 PM

View Postno2pencil, on 28 Jan, 2010 - 09:07 PM, said:

Every C/C++ project must have a main() function as it's the entry point to the program. What is your return 0 for if you have no function? What's it returning from, & to? You need main.



Ok, but i can not figure out where to put that main and get it to work! Will I put it after the class declaration or the constructor?
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,879
  • Joined: 10-May 07

Re: Declaration has no Storage

Posted 28 January 2010 - 10:12 PM

Try both, that's what I did. Each one gets different errors.
Was This Post Helpful? 0
  • +
  • -

#11 tarheelfan_08  Icon User is offline

  • D.I.C Regular

Reputation: -2
  • View blog
  • Posts: 256
  • Joined: 24-January 10

Re: Declaration has no Storage

Posted 28 January 2010 - 10:20 PM

View Postno2pencil, on 28 Jan, 2010 - 09:12 PM, said:

Try both, that's what I did. Each one gets different errors.



I tried both like you said and it seems better to place it after the constructor. Now I am getting an error with undeclared variables and I need to figure out how to fix that!

Ok everyone just as an update, i added my main and now I am getting a undeclared variable error with my cin's

#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;

	//Class Declaration
	class Car
	{
		private:
			string make;  //make
			string	model; // model
			string	color;  // color 
			string liscensePlate;  // liscense plate number
			int	year;  // year
			int mileage;  // miles on car

		public:
			Car(); //constructor			
			string getMake;
			string getModel;
			string getColor;
			string getLiscensePlate;
			int getYear;
			int getMileage;
			void validation(int);
			void printCarDetails();
			void CarDetails ( string, string, string, string, int, int);

	};


	// Constructor to initialize each object to always start the same way
	Car::Car()
	{
		make = ""; 
		model = ""; 
		color = "";   
		liscensePlate = "";  
		year = 0;
		mileage = 0;
	}
	
	
int main()
{

	cout << "What is the car make? ";
	cin >> make;
	cout << "What the car model? ";
	cin >> model;
	cout << "What year is the car? ";
	cin >> year;
	cout << "What color is the car? ";
	cin >> color;
	cout << "What is the liscense plate number? ";
	cin >> liscensePlate;
	cout << "How many miles does the car have on it? ";
	cin >> mileage;
	while (mileage < 0 )
	{	
		cout << " This is not a valid mileage.\n";
		cout << " Enter the miles for this car: ";
		cin >> mileage;
	}
	
	cout << "The current car is a " << year << " " << color << " " << model << " with " << miles << " miles!  And the Liscense Plate number is " << liscensePlate << endl; 
	
return 0;			

}


Was This Post Helpful? 0
  • +
  • -

#12 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 855
  • View blog
  • Posts: 2,338
  • Joined: 20-August 07

Re: Declaration has no Storage

Posted 29 January 2010 - 08:33 AM

You haven't declared any of your variables in main - in fact, you seem to be making random guesses. I strongly suggest you spend time reading your book or reference material about how classes work and try to compile and run some small examples for yourself, because it seems like you're trying to walk before you can crawl.

This post has been edited by Bench: 29 January 2010 - 08:34 AM

Was This Post Helpful? 0
  • +
  • -

#13 Anarion  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,456
  • Joined: 16-May 09

Re: Declaration has no Storage

Posted 29 January 2010 - 08:58 AM

Maybe you should not step into classes right now, try to master basic sections first :)
Was This Post Helpful? 0
  • +
  • -

#14 suresh.chereddy@gmail.com  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 06-February 08

Re: Declaration has no Storage

Posted 29 January 2010 - 09:40 AM

Every C/C++ project must have a main() function as it's the entry point to the program. What is your return 0 for if you have no function? What's it returning from, & to? You need main.
Was This Post Helpful? 0
  • +
  • -

#15 Anarion  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,456
  • Joined: 16-May 09

Re: Declaration has no Storage

Posted 29 January 2010 - 09:47 AM

no2Pencil said:

Every C/C++ project must have a main() function as it's the entry point to the program. What is your return 0 for if you have no function? What's it returning from, & to? You need main.

Why do you copy no2's answer? you did things like this in other posts before

This post has been edited by Anarion: 29 January 2010 - 09:48 AM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3