C++ 在头文件中使用枚举'___'而没有先前的声明?
C++ Use of enum '___' without previous declaration in header file?
我正在尝试使用枚举来表示交通模拟中的街道和方向。我遇到了一个问题,即尝试将枚举放入构造函数并将其放入 Vehicle 构造函数中。
当我尝试编译车辆时出现错误。 - 在没有事先声明的情况下使用枚举"街道/方向"。 - 在","令牌之前有两个预期的标识符,我在其中声明了车辆构造函数
这是我到目前为止所拥有的。
//Street.h
#ifndef STREET_H
#define STREET_H
enum street
{
Main = 1,
Church,
};
#endif
//Direction.h
#ifndef DIRECTION_H
#define DIRECTION_H
enum direction
{
E = 1,
W,
N,
};
#endif
//Vehicle.h
#ifndef VEHICLE_H
#define VEHICLE_H
#include "Street.h"
#include "Direction.h"
class Vehicle
{
private:
int vehicleNumber;
int arrivalTime;
int departureTime;
enum street;
enum direction;
public:
Vehicle(int, enum, enum, int);
};
#endif
Vehicle(int, enum, enum, int);
这是不正确的,您应该使用所需的枚举类型的名称(在本例中为street
,direction
而不是关键字 enum
。
这些成员变量也是如此(感谢@Unda注意到)。
相关文章:
- 访问在 C++ 结构中声明的枚举变量
- 如何使用默认值将枚举声明为 extern
- 如何转发声明枚举?
- 如何将枚举类转发声明为模板化类的内部类?
- 枚举前向声明与头文件
- C++:如何在声明枚举类的模板类主体之外定义枚举类?
- 在C++代码中使用的 C 标头中向前声明枚举
- 在哪里声明枚举
- 在模板参数内向前声明枚举类
- 在C++14中,在哪个作用域中声明了重新声明枚举的非范围枚举器
- 在C中定义的C++中正向声明枚举
- 在不膨胀命名空间的情况下在C++中声明枚举的好方法
- 声明枚举标识符的基础类型
- 为什么在向前声明枚举时必须提供枚举的大小?
- 前向声明枚举类不起作用
- 在运行时有条件地声明枚举(C++)
- 我可以传递前向声明枚举的值吗?
- c++ -对声明枚举感到困惑
- c++:在类内部从外部声明枚举器,以便可以在私有成员中使用
- 在声明枚举之前使用它