私はC++クラスの車のクラスプログラムを作成しています。Visual Studioで使用できる唯一の部分は "string and make"と関係があります。私はそれらをコメントし、プログラムは正常に動作します。私たちの先生は3つの別々のページに分割するよう頼んだ。タイトルに記載されているエラーは、MISSING TYPE SPECIFIERです。必要なのは、 "namespace std;を使用していました" car.hファイルに格納します。エラー:型指定子がありません
ありがとうございました。ここで
#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.h
#pragma once
#ifndef CAR_H
#define CAR_H
// Car class declaration
class Car
{
private:
string make;
int year;
int speed;
public:
int myCar(int year, string make, int speed);
int setYear(int carYear);
int setSpeed(int carSpeed);
string setMake(string carMake);
int getYear();
int getSpeed();
string getMake();
void accelerate();
void brake();
};
であり、ここで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;
}
//***
あなたの質問に何か重要なものがありません。それは実際の質問でしょう。 "私の宿題はコンパイルされません"、コンパイルエラーを表示しなくても、質問ではありません。 –
宿題について質問するのは特に間違っていませんが、はい、質問してください。これまでに試したことを示し、あなたのために働いている/働いていないものを広げてください。一般に、「自分のコードは機能しません」というのは、応答を得るための非常に良い方法ではありません。具体的には、コンパイル時にどのようなエラーが発生するのですか。 – user2366842
文字列を返すようにsetMakeを定義しましたが、戻り値を使用せず、何も返しません。 – stark