C+中的错误消息+;:函数/变量“;未在此范围内声明“;,变量";“是私人的”; 我对编程和C++特别陌生,我正在尝试编写代码:汽车经销商的方块。应该可以买卖车辆,并打印出有关车辆的信息。不同的车辆都分为不同的等级。在主功能中,我实现了一个带有选择菜单的界面,用于可能的操作,如出售汽车
尽管我已经在头文件(watercraftType.h、watercraft.h、两栖类.h、motorbike.h、car.h、vehicle.h、vehicle.h、vehicleDealer.h)中声明了函数/变量,并将这些函数/变量包含在各自的源文件和主函数中(根据需要),但我还是不断收到我不理解的错误消息(如“未在此范围内声明”). 我收到以下错误消息: 船艇中的错误消息。h:“双船艇:最大深度”为 私有的“WatercraftType::type”是私有的 car.h中的错误消息:“int car::doors”是私有的 我不明白为什么错误信息会在测试过程中出现 船舶中变量的声明。在车里。h错误 消息在类构造函数的声明期间显示 两栖动物.cpp中的错误消息:“catchYear”未在此文件中声明 范围“AVC”、“喷水”、“螺旋桨”未在此范围内声明 我已包括标题“vehicle.h”,其中包括声明 对于catchYear(),以及文件中的头文件“两栖动物.h”,其中 包括标题“watercraft.h”。“船艇.h”包括 带有enum类声明的“watercraftType.h” 船艇类型 main.cpp中的错误消息:在案例2中:“Motorbike”、“Motorrad1”被删除 未在此范围内声明;之前需要类型说明符 “摩托车”;在案例3中,对于:cin>>vType;:“操作员>>不匹配” (操作数类型为“std::istream{aka std:basic_istream}”和 “船舶类型”) 我不明白为什么我会收到这些错误信息,因为我是 使用与案例1中Car类完全相同的语法C+中的错误消息+;:函数/变量“;未在此范围内声明“;,变量";“是私人的”; 我对编程和C++特别陌生,我正在尝试编写代码:汽车经销商的方块。应该可以买卖车辆,并打印出有关车辆的信息。不同的车辆都分为不同的等级。在主功能中,我实现了一个带有选择菜单的界面,用于可能的操作,如出售汽车,c++,codeblocks,C++,Codeblocks,尽管我已经在头文件(watercraftType.h、watercraft.h、两栖类.h、motorbike.h、car.h、vehicle.h、vehicle.h、vehicleDealer.h)中声明了函数/变量,并将这些函数/变量包含在各自的源文件和主函数中(根据需要),但我还是不断收到我不理解的错误消息(如“未在此范围内声明”). 我收到以下错误消息: 船艇中的错误消息。h:“双船艇:最大深度”为 私有的“WatercraftType::type”是私有的 car.h中的错误消息:“
//vehicle.h
#ifndef VEHICLE_H_INCLUDED
#define VEHICLE_H_INCLUDED
#include <string>
class Vehicle
{
public:
std::string id;
std::string model;
virtual ~Vehicle();
virtual void printVehicle();
static bool checkID(std::string vId);
int catchYear();
private:
int year;
protected:
Vehicle(std::string vId, std::string vModel, int vYear);
};
#endif // VEHICLE_H_INCLUDED
//car.h
#ifndef CAR_H_INCLUDED
#define CAR_H_INCLUDED
#include "vehicle.h"
#include <string>
class Car : public Vehicle
{
public:
Car(std::string vId, std::string vModel, int vYear, int vDoors, bool vRightHandDrive);
void printVehicle();
private:
int doors;
bool rightHandDrive;
};
#endif // CAR_H_INCLUDED
//watercraft.h
#ifndef WATERCRAFT_H_INCLUDED
#define WATERCRAFT_H_INCLUDED
#include "watercraftType.h"
class Watercraft
{
private:
double maxdepth;
WatercraftType type;
protected:
Watercraft(double vMaxdepth, WatercraftType vType);
void printVehicle();
};
#endif // WATERCRAFT_H_INCLUDED
//watercraftType.h
#ifndef WATERCRAFTTYPE_H_INCLUDED
#define WATERCRAFTTYPE_H_INCLUDED
enum class WatercraftType {AVC, WATERJET, PROPELLER};
#endif // WATERCRAFTTYPE_H_INCLUDED
//amphibian.h
#ifndef AMPHIBIAN_H_INCLUDED
#define AMPHIBIAN_H_INCLUDED
#include "car.h"
#include "watercraft.h"
class Amphibian : public Car, public Watercraft
{
public:
Amphibian(std::string vId, std::string vModel, int vYear, int vDoors, double vMaxdepth, WatercraftType vType);
void printVehicle();
};
#endif // AMPHIBIAN_H_INCLUDED
//amphibian.cpp
#include "amphibian.h"
#include "vehicle.h"
#include <iostream>
//Amphibian Konstruktor
Amphibian::Amphibian(std::string vId, std::string vModel, int vYear, int vDoors, double vMaxdepth, WatercraftType vType) :
Car(vId, vModel, vYear, vDoors, false),
Watercraft(vMaxdepth, vType)
{}
//Methode printVehicle
void Amphibian::printVehicle()
{
std::cout << "Id: " << id << "\n";
std::cout << "Model: " << model << "\n";
std::cout << "Year: " << std::to_string(catchYear()) << "\n";
std::cout << "Doors: " << std::to_string(doors)<< "\n";
std::cout << "MaxDepth: " << std::to_string(maxdepth) << "\n";
switch(type)
{
case AVC: std::cout << "Type: " << "AVC" << "\n"; break;
case WATERJET: std::cout << "Type: " << "WATERJET" << "\n"; break;
case PROPELLER: std::cout << "Type: " << "PROPELLER" << "\n"; break;
default: std::cout << "Type: Unknown WatercraftType" << "\n";
}
}
//main.cpp
#include "vehicle.h"
#include "car.h"
#include "motorbike.h"
#include "amphibian.h"
#include "vehicleDealer.h"
#include <iostream>
using namespace std;
int main()
{
while (true)
{
VehicleDealer Haendler ("Dealer");
int auswahl;
cout << "Willkommen beim Autohändler: " << Haendler.name << ".\n"
"Was möchten Sie tun?\n"
"Drücken Sie die entsprechende Zahl auf der Tastatur.\n"
"1 - Auto hinzufügen.\n"
"2 - Motorrad hinzufügen.\n"
"3 - Amphibienfahrzeug hinzufügen.\n"
"4 - Fahrzeug entfernen.\n"
"5 - Fahrzeuge anzeigen.\n"
"Sonstige Einzelzahl: Autohändler verlassen.\n";
cin >> auswahl;
switch(auswahl)
{
case 1:
{
string vId;
string vModel;
int vYear;
int vDoors;
bool vRightHandDrive;
cout << "Bitte geben Sie die nötigen Paramter zur Erstellung eines Autos ein.\n"
"Bitte geben Sie die Fahrzeugnummer (7-stellig) ein.\n";
cin >> vId;
if (Vehicle::checkID(vId) == false)
{
cout << "Die Nummer ist falsch. Bitte geben Sie die Fahrzeugnummer (7-stellig) erneut ein.\n";
cin >> vId;
}
cout << "Bitte geben Sie die Modellbezeichnung ein.\n";
cin >> vModel;
cout << "Bitte geben Sie die Anzahl der Türen ein.\n";
cin >> vDoors;
cout << "Bitte geben Sie das Herstellungsjahr des Autos ein.\n";
cin >> vYear;
cout << "Bitte geben Sie an, ob es sich bei dem Auto um einen Rechtslenker handelt.\n";
cin >> vRightHandDrive;
Car* Auto1;
Auto1 = new Car(vId, vModel, vYear, vDoors, vRightHandDrive);
if (Haendler.buyVehicle((Vehicle*)Auto1) == false)
{
cout << "Das Auto konnte nicht hinzugefügt werden.\n";
}
break;
}
case 2:
{
string vId;
string vModel;
int vYear;
cout << "Bitte geben Sie die nötigen Paramter zur Erstellung eines Motorrads ein.\n"
"Bitte geben Sie die Fahrzeugnummer (7-stellig) ein.\n";
cin >> vId;
if (Vehicle::checkID(vId) == false)
{
cout << "Die Nummer ist falsch. Bitte geben Sie die Fahrzeugnummer (7-stellig) erneut ein.\n";
cin >> vId;
}
cout << "Bitte geben Sie die Modellbezeichnung ein.\n";
cin >> vModel;
cout << "Bitte geben Sie das Herstellungsjahr des Motorrads ein.\n";
cin >> vYear;
Motorbike* Motorrad1;
Motorrad1 = new Motorbike(vId, vModel, vYear);
if (Haendler.buyVehicle((Vehicle*)Motorrad1) == false)
{
cout << "Das Motorrad konnte nicht hinzugefügt werden.\n";
}
break;
}
case 3:
{
string vId;
string vModel;
int vYear;
int vDoors;
double vMaxdepth;
WatercraftType vType;
cout << "Bitte geben Sie die nötigen Paramter zur Erstellung eines Amphibienfahrzeugs ein.\n"
"Bitte geben Sie die Fahrzeugnummer (7-stellig) ein.\n";
cin >> vId;
if (Vehicle::checkID(vId) == false)
{
cout << "Die Nummer ist falsch. Bitte geben Sie die Fahrzeugnummer (7-stellig) erneut ein.\n";
cin >> vId;
}
cout << "Bitte geben Sie die Modellbezeichnung ein.\n";
cin >> vModel;
cout << "Bitte geben Sie das Herstellungsjahr des Amphibienfahrzeugs ein.\n";
cin >> vYear;
cout << "Bitte geben Sie die Anzahl der Türen ein.\n";
cin >> vDoors;
cout << "Bitte geben Sie die maximale Tiefe als Gleitkommazahl (mit Punkt) an.\n";
cin >> vMaxdepth;
cout << "Bitte geben Sie den Antriebstyp an (AVC, WATERJET, PROPELLER).\n";
cin >> vType;
Amphibian* Amphibian1;
Amphibian1 = new Amphibian(vId, vModel, vYear, vDoors, vMaxdepth, vType);
if (Haendler.buyVehicle((Vehicle*)Amphibian1) == false)
{
cout << "Das Amphibienfahrzeug konnte nicht hinzugefügt werden.\n";
}
break;
}
case 4:
{
string vId;
cout << "Bitte geben Sie die Fahrzeugnummer (7-stellig) des Fahrzeugs ein, das Sie entfernen wollen.\n";
cin >> vId;
if (Haendler.sellVehicle(vId) == false)
{
cout << "Das Fahrzeug konnte nicht entfernt werden.\n";
}
break;
}
case 5:
{
cout << "Alle vorhandenen Fahrzeuge werden ausgegeben.\n";
Haendler.printVehicles();
break;
}
default:
{
cout << "Sie haben eine sonstige Ziffer gewählt. Das Programm wird beendet.\n";
return 0;
}
}
}
return 0;
}
//vehicle.h
#如果不包括车辆
#定义包含的车辆
#包括
等级车辆
{
公众:
std::字符串id;
std::字符串模型;
虚拟车辆();
虚拟车辆();
静态bool-checkID(std::string-vId);
整年();
私人:
国际年;
受保护的:
车辆(标准:字符串vId,标准:字符串vModel,整数vYear);
};
#endif//包括车辆
//汽车
#如果不包括汽车,则
#定义包含的车辆
#包括“vehicle.h”
#包括
车辆类别:公共车辆
{
公众:
汽车(标准:字符串视频,标准:字符串V模型,整数vYear,整数vDoors,布尔vRightHandDrive);
车辆无效();
私人:
内部门;
布尔右舵驾驶;
};
#endif//CAR\u H\u包括在内
//船艇
#ifndef船舶包括在内
#定义包括在内的船舶
#包括“watercraftType.h”
等级船舶
{
私人:
双最大深度;
船艇型;
受保护的:
船艇(双V轴深度,船艇类型V型);
车辆无效();
};
#endif//包括船艇
//船舶类型.h
#ifndef船舶类型包括
#定义包括的船舶类型
枚举类船舶类型{AVC,喷水,螺旋桨};
#endif//包括船艇类型
//两栖动物
#ifndef包括两栖动物
#包括定义两栖动物
#包括“car.h”
#包括“船艇.h”
两栖类:公共汽车、公共船舶
{
公众:
两栖动物(标准::字符串vId,标准::字符串V模型,整数V年,整数V门,双V最大深度,船艇类型V型);
车辆无效();
};
#endif//包括两栖动物
//两栖动物
#包括“两栖动物.h”
#包括“vehicle.h”
#包括
//两栖类昆虫
两栖动物::两栖动物(std::字符串vId,std::字符串vModel,int vYear,int vDoors,双vMaxdepth,船艇类型vType):
汽车(视频、虚拟模型、虚拟年、虚拟门、假),
船艇(vMaxdepth,vType)
{}
//印刷车方法
void两栖动物::printVehicle()
{
std::cout您无法访问Watercraft:maxdepth和WatercraftType::type,因为您已将它们声明为私有。为了在您的两栖类中使用它们,您需要将它们声明为公共或私有
要修复两栖动物::printVehicle()中的错误,需要编写
`void Amphibian::printVehicle()
{
std::cout << "Id: " << id << "\n";
std::cout << "Model: " << model << "\n";
std::cout << "Year: " << std::to_string(catchYear()) << "\n";
std::cout << "Doors: " << std::to_string(doors)<< "\n";
std::cout << "MaxDepth: " << std::to_string(maxdepth) << "\n";
switch(type)
{
case WatercraftType::AVC: std::cout << "Type: " << "AVC" << "\n"; break;
case WatercraftType::WATERJET: std::cout << "Type: " << "WATERJET" << "\n"; break;
case WatercraftType::PROPELLER: std::cout << "Type: " << "PROPELLER"<< "\n"; break;
default: std::cout << "Type: Unknown WatercraftType" << "\n";
}
}`
`void两栖动物::printVehicle()
{
std::cout我敢打赌,您至少可以删除90%的代码,但仍然会得到错误。@Brabrara此语句std::cout中使用的变量doors在哪里