【发布时间】:2018-02-12 04:50:43
【问题描述】:
我有一个关于在我的作业中使用enum 和struct 的问题,我在理解上有点困难。
首先,这是我们老师给我们的代码示例。
enum MonthType {JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC};
struct WeatherType
{
int avgHiTemp;
int avgLoTemp;
float actualRain;
float recordRain;
};
然后作业说声明WeatherType 组件的一维数组类型WeatherListType,由MonthType 类型的值索引。当我尝试通过编码来做到这一点时:
typedef WeatherType WeatherListType[MonthType];
我收到了这些错误:
problem5.cpp:19:47: error: expected primary-expression before ']' token
typedef WeatherType WeatherListType[MonthType];
^
problem5.cpp:21:2: error: 'WeatherListType' was not declared in this scope
WeatherListType yearlyWeather;
我只是对问题所在感到困惑,如果我走在正确的轨道上,我到底做错了什么?
【问题讨论】: