I m 创建简单构造和启动一个阵列:
// Construtor
Cinema::Cinema(){
// Initalize reservations
for(int i = 0; i < 18; i++){
for(int j = 0; j < 12; j++){
setReservation(i, j, 0);
}
}
// Set default name
setMovieName("N/A");
// Set default price
setPrice(8);
}
保留职能:
void Cinema::setReservation(int row, int column, int reservation){
this->reservations[row][column] = reservation;
}
既定职能:
void Cinema::setMovieName(std::string movieName){
this->movieName = movieName;
}
For some odd reason when I run the program, the setMovieName function gives the following error: "Program Received Signal: EXC_BAD_ACCESS"
If I take out the for-loop that initializes the array of reservations, the problem goes away and the movie name is set without any problems. Any idea what I m doing wrong?
这是电影档案:
#ifndef Cinema_h
#define Cinema_h
class Cinema{
private:
int reservations[17][11];
std::string movieName;
float price;
public:
// Construtor
Cinema();
// getters/setters
int getReservation(int row, int column);
int getNumReservations();
std::string getMovieName();
float getPrice();
void setReservation(int row, int column, int reservation);
void setMovieName(std::string movieName);
void setPrice(float price);
};
#endif