C++中的类:声明实例

C++中的类:声明实例,c++,class,C++,Class,我已经咨询了很多网站,但还没有成功地完成我的代码 我正在尝试编写一些代码,一旦用户提供信息,就可以输出有关汽车的信息。编译后,编译器说声明没有声明任何内容。代码如下: #include <iostream> #include <string> #include "Car.h" using namespace std; Car::Car() { } void Car::accel() { speed += 5; } void Car::

我已经咨询了很多网站,但还没有成功地完成我的代码

我正在尝试编写一些代码,一旦用户提供信息,就可以输出有关汽车的信息。编译后,编译器说声明没有声明任何内容。代码如下:

 #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

}
和车头。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

每次我的对象自动出现时,我都会出现缺少分号的错误;在自动之前和自动之前预期的主表达式。有什么问题吗?

自动是一个关键词。您需要选择其他名称。

自动是一个关键字。您需要选择一个不同的名称。

发布真正的错误消息和头文件。哪个编译器说的东西没有声明任何东西?我建议您切换到一些不提供类似笑话错误消息的编译器。发布真正的错误消息和头文件。哪个编译器说的东西没有声明任何东西?我建议您切换到一些编译器,它不会给出这样的错误消息。为了补充艾伦的回答,我建议你给它起个名字叫vehicule或者别的什么,避免使用auto。我现在觉得很可笑。我将对象命名为automobile,现在它运行。非常感谢。一点也不可笑-错误消息没有帮助。我敢打赌,你找不到任何人能正确列出所有的关键词。为了补充艾伦的回答,我建议你给它起个名字叫vehicule或者别的什么,避免使用auto。我现在觉得很可笑。我将对象命名为automobile,现在它运行。非常感谢。一点也不可笑-错误消息没有帮助。我打赌你找不到任何人能正确列出所有关键词。