我收到有关无效使用非静态成员的错误以及结构成员无法正常工作的其他问题,我无法理解问题所在,谢谢。
#include <iostream>
#include <string>
using namespace std;
struct classroom {
int RoomNumber;
int NumberOfChairs;
int NumberOfStudents;
int ListOfStudents[NumberOfStudents];
string LectureName;
bool Window, Projector, Available;
}classroom;
int main() {
cout << "Please enter your room number" << endl;
cin >> classroom.RoomNumber;
cout << "Enter the name of the Lecture" << endl;
cin >> classroom.LectureName;
cout << "Enter number of students" << endl;
cin >> classroom.NumberOfStudents;
cout << "Enter " << classroom.NumberOfStudents << " Student Names" << endl;
cin >> classroom.ListOfStudents;
cout << "Enter number of chairs" << endl;
cin >> classroom.NumberOfChairs;
cout << "Are there any Windows? (Y/N)" << endl;
cin >> classroom.Window;
cout << "Are there any Projectors? (Y/N)" << endl;
cin >> classroom.Projector;
cout << "Are there any Available? (Y/N)" << endl;
cin >> classroom.Available;
return 0;
}
错误
prog.cpp:10:5: error: invalid use of non-static data member ‘classroom::NumberOfStudents’
int NumberOfStudents;
^
prog.cpp:11:20: error: from this location
int ListOfStudents[NumberOfStudents];
^
prog.cpp: In function ‘int main()’:
prog.cpp:28:18: error: ‘struct classroom’ has no member named ‘ListOfStudents’
cin >> classroom.ListOfStudents;
^