错误:缺少类型说明符 我正在为我的C++类编写一个Car类程序,而VisualStudio唯一的部分就是与String和Studio无关。我把它们注释掉了,程序运行得很好。老师让我们把它分成三页。标题中发布的错误缺少类型说明符。结果证明所需要的只是使用名称空间std;在车里

错误:缺少类型说明符 我正在为我的C++类编写一个Car类程序,而VisualStudio唯一的部分就是与String和Studio无关。我把它们注释掉了,程序运行得很好。老师让我们把它分成三页。标题中发布的错误缺少类型说明符。结果证明所需要的只是使用名称空间std;在车里,c++,string,C++,String,谢谢你的帮助 #include "stdafx.h" #include <iostream> #include <string> #include <iomanip> #include "Car.h" using namespace std; int main() { // Declare car object Car myCar; int sp

谢谢你的帮助

    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include "Car.h"
    using namespace std;


    int main()
    {
        // Declare car object
        Car myCar;
        int speed = 0, year;
        string make;


        cout << "This program will help you with your Car!" << endl;   //         intro message

        cout << "Please enter the Year" << endl;   // store year
        cin >> year;

        cout << "Please enter the Make of the car" << endl;   // store make
        cin >> make;


        // call member functions to set car year and make.
        myCar.setYear(2013);
        myCar.setMake("Mustang GT");

        // call member functions to get car year and make
        cout << "Your car's current year is: " <<  myCar.getYear() << endl;
        cout << "Your car's current make is: " << myCar.getMake;
        cout << "Your car's current speed is : " << speed << " mph" << endl;





        return 0;
     }
这是Car.cpp

#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip>
#include "Car.h"
using namespace std;


//***
//myCar
//**
int Car::myCar(int year, string make, int speed)
{
    int setYear(int year);
    string setMake(string make);
    return year, make, speed;
}


//**********
// setYear
//*********
int Car::setYear(int carYear)
{
    year = carYear;
    return carYear;

}


//************
// setMake
//************
string Car::setMake(string carMake)
{

    make = carMake;


}
//***    

//***
//setSpeed
//***
int Car::setSpeed(int carSpeed)
{
    speed = carSpeed;
    return carSpeed;


}
//***

//***
//getYear
//***
int Car::getYear()
{

    return year;

}
//***

//***
//getMake
//***
string Car::getMake()
{
    return make;

}


//***
//getSpeed
//***
int Car::getSpeed()
{

    return speed;

}
//***

//***
// Accelerate
//***
void Car::accelerate()
{
    int speed = 0;
    speed += 5;


}
//***

//***
// Brake
//***
void Car::brake()
{
    int speed = 0;
    speed -= 5;

}
//***
在setMake函数中,它声明为字符串,但不返回值。我相信您忘记返回传递的值

//************
// setMake
//************
string Car::setMake(string carMake)
{

    make = carMake;
    return make; // This line should do the trick

}
我建议下次仔细看看编译器的输出,因为它可能会给你一个行号,甚至是问题所在函数的名称


旁注:集合函数通常声明为void,因为它们通常不需要返回任何内容。

您的问题中缺少一些重要的内容。这将是一个实际的问题。我的家庭作业没有编译,甚至没有显示编译错误,这不是一个问题。问关于家庭作业的问题没有什么特别的错误,但是是的,问一个问题。展示你迄今为止所做的尝试,并扩展哪些对你有效/无效。一般来说,我的代码不起作用并不是获得响应的好方法。更具体地说,当您尝试和编译时会发生什么错误,以及您尝试和修复这些错误的步骤是什么?您定义了setMake以返回字符串,但您不使用返回值,也不返回任何内容。我认为缺少类型说明符已经足够清楚了。我不明白这个网站。你对你的问题过于详细,你会被巨魔否决。你给出了代码,直截了当地说出了标题和问题,你被巨魔们否决了。谢谢你,这很有帮助。结果是,我的老师不知道为什么visual Studio决定了uising名称空间std;车上的文件不见了。我的老师说,既然它与主驱动器相连,它就不需要了。但这就是导致类型说明符错误的原因。
//************
// setMake
//************
string Car::setMake(string carMake)
{

    make = carMake;
    return make; // This line should do the trick

}