在头文件中:
typedef struct apartment_t* Apartment;
typedef enum { EMPTY, WALL } SquareType;
struct apartment_t {
SquareType** squares;
int width;
int length;
int price;
};
源文件中的:
int apartmentTotalArea(Apartment apartment) {
int countEmpty = 0;
for (int i=0;i<apartment->length;i++)
for (int j=0;j<apartment->width;j++) {
SquareType Square = apartment->squares[i][j];
switch(Square) {
case Square.EMPTY: // Bad
countEmpty++;
break;
case Square.WALL: // Bad
break;
}
}
此函数计算给定2d数组中的空白点。我在交换机中遇到问题,它会将这两种情况都标记为错误的陈述。我的代码出了什么问题?谢谢。
答案 0 :(得分:1)
代码中没有Square.EMPTY
或Square.WALL
这样的内容。使用:
switch(Square) {
case EMPTY: // Juse EMPTY, not Square.EMPTY
countEmpty++;
break;
case WALL:
break;
}