1

I have consulted many websites but have not successfully completed my code.

I am trying to write some code that spits out information about a car, once the user provides information. After compiling, the compiler says that "declaration does not declare anything." Here's the code:

 #include <iostream>
    #include <string>
    #include "Car.h"

using namespace std;

Car::Car()
{

}

void Car::accel()
{
     speed += 5;
}

void Car::brake()
{
     speed -= 5;
}

void Car::setSpeed(int newSpeed)
{
     speed = newSpeed;
}

int Car::getSpeed()
{
    return speed;
}

void Car::setMake(string newMake)
{
     make = newMake;
}

string Car::getMake()
{
     return make;
}

void Car::setYearModel(int newYearModel)
{
     yearModel = newYearModel;
}

int Car::getYearModel()
{
    return yearModel;
}

int main()
{
    Car auto; //instance of class Car
    int autoYear; //year of auto
    string autoMake; //make of auto
    int autoSpeed; //speed of auto

    cout << "Enter the year model of your car. ";
    cin >> autoYear;
    cout << "Enter the make of your car. ";
    cin >> autoMake;

    auto.setYear(autoYear); //stores input year
    auto.setMake(autoMake); //stores input make

}

And the header, Car.h:

#include <iostream>
#include <string>

using namespace std;

#ifndef CAR_H
#define CAR_H

class Car
{
      private:
         int yearModel;
         string make;
         int speed;
      public:
         Car();
         void accel();
         void brake();
         void setSpeed(int newSpeed);
         int getSpeed();
         void setMake(string newMake);
         string getMake();
         void setYearModel(int newYearModel);
         int getYearModel();
};

#endif

I also have errors for missing semicolons every time my object auto appears ("expected ; before auto" and "expected primary-expression before auto"). What could be the problem?

2
  • 1
    Post the real error messages and also the header file. Commented Nov 24, 2013 at 21:03
  • 3
    Which compiler says "something that doesn't declare anything"? I suggest you to switch to some compiler that doesn't give joke error messages like that. Commented Nov 24, 2013 at 21:03

1 Answer 1

4

auto is a keyword. You'll need to pick a different name.

Sign up to request clarification or add additional context in comments.

3 Comments

Indeed. To add to Alan answer, I'd recommend you to name it vehicule or something else and avoid using auto.
I feel ridiculous now. I named the object automobile instead, now it runs. Thank you so much.
Not ridiculous at all - the error messages weren't helpful. And I bet you can't find anyone who can correctly list all the keywords.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.