0

我在我的航班预订系统程序中收到错误消息“未解析的重载类型>[int] for array subscript”。

我要做的是设置它,以便如果 [j] 等于 0,1,2,3... 它将相应地显示为 A,B,C,D。在我开始这样做之前,我的程序至少已经编译好了。</p>

// Flight Class - Scotia 2
// 
// Contains information on seating (array), space available and return to menu option.


#include <iostream>
#include <string>
#include "passenger.h"
#include "Seat.h"

using namespace std;

/*struct Seat
        {
            int Available;
            std::string fullName;
        };// End of struct*/

class Flight
{

public:
//default constructor
Flight()
{
//initialise all seat numbers
for(int i=0;i<4;i++)
for(int j=0;j<6;j++)
    {// assigns seats as 1A, 1B etc...
    seatPlan[i][j].setRow(row);
    if(j==0)
    seatPlan[i][j].setCol('A');
    else if(j==1)
    seatPlan[i][j].setCol('B');
    else if(j==2)
    seatPlan[i][j].setCol('C');
    else if(j==3)
    seatPlan[i][j].setCol('D');
    }
}

Seat seatArray[4][6];

    void seatPlan()
    {
        for (int ROW=0;ROW<4;ROW++)
        {
            for (int COL=0;COL<6;COL++)
                {
                    cout << seatPlan[i][j].getSeatRow();
                }
        }
        // End of for loop
    }// End of seatPlan function

//method which returns true if seat is Available and false otherwise
bool getAvailable(int i, int j)
{
    if(seatArray[i][j].Available == 0)
    return true; //seat available
    else
    return false; //seat occupuied
}

string getName(int i,int j){return seatArray[i][j].fullName;}

void setAvailable(int i, int j, int a){seatArray[i][j].Available = a;}
void setName(int i,int j, string name){seatArray[i][j].fullName = name;}

private:
//variables
int row;
char col;

};// End of Flight class

以上是我的 flight.h 文件,其中包含 Flight 类。错误消息指向我的构造函数,其中包含的所有行都重复该消息seatPlan[i][j].setCol('A');,依此类推。

我还将包含“seat.h”文件,以防万一。

#ifndef SEAT
#define SEAT

#include <iostream>

using namespace std;

class Seat
{

    public:
    //deafult constructor
    Seat(){available = true;}

    //accessor methods
    void setRow(int row){seatRow = row;}
    void setCol(char col){seatCol = col;}

    int getSeatRow(){return seatRow;}
    char getSeatCol(){return seatCol;}

    bool isAvailable(){return available;}
    bool switchAvailable(){
    if(available)
    available = false;
    else
    available = true;
    }

    private:
    bool available;
    int seatRow;
    char seatCol;
};

#endif
4

2 回答 2

1

void seatPlan()是一种方法,您将其视为数组。你的意思是seatArray相反吗?

if(seatArray[i][j].Available == 0)
return true; //seat available
else
return false; //seat occupuied

? 真的吗?为什么不只是

return seatArray[i][j].Available == 0;

(假设你修复了之前的错误)

于 2013-01-17T20:19:15.100 回答
1
seatPlan[i][j].setRow(row);

这是问题所在。seatPlan不是数组。它是函数的名称。

你的意思是seatArray。所以应该是:

seatArray[i][j].setRow(row);

一个建议:考虑使用std::array

std::array<std::array<Seat,6>,4> seatArray;

代替

Seat seatArray[4][6];
于 2013-01-17T20:19:30.343 回答