Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unfamiliar C++ syntax while I'm trying to study data structures in C++

Tags:

c++

I'm about to learn Data Structures in C++ but I'm suffering from facing to unfamiliar C++ syntax , like :

enum SeatStatus SeaList[Max_Seats];

all I know about using "enum" in C++ is like :

enum direction{up,right,down,left} ; // 0 , 1 , 2 , 3

For analyzing an algorithm that is implemented in C++ programming language , I face to a huge amount of unfamiliar codes. Please help me fix this matter out. Thanks to stackoverflow community .

like image 430
Erfan Avatar asked Dec 12 '22 01:12

Erfan


1 Answers

It is declaring an array of enums of type SeatStatus. The array is named SeaList. This presupposes enum SeatStatus has been defined previously.

This formulation might look more familiar:

SeatStatus SeaList[Max_Seats];

It is handy in situations where there is something else called SeatStatus. For example

enum SeatStatus { GOOD, BAD };
const int Max_Seats = 42;

int main()
{
  int SeatStatus;                     // Oh-oh, another SeatStatus!
  SeatStatus SeaList[Max_Seats];      // ERROR: SeatStatus is int object
  enum SeatStatus SeaList[Max_Seats]; // OK, we mean the enum
}
like image 166
juanchopanza Avatar answered May 19 '23 06:05

juanchopanza