0

I'm getting the error message 'Unresolved overloaded type>[int] for array subscript' in my flight-booking-system program.

What I'm trying to do is set it so that if [j] is equal to 0,1,2,3... it will display accordingly as A,B,C,D. Until I started doing this my program at least compiled。

// 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

The above is my flight.h file which contains the Flight class. The error message points to my constructor, with the message repeating for all the lines within that contain seatPlan[i][j].setCol('A'); and so on.

I'll include the 'seat.h' file also, just in case it's relevant.

#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
6
  • In regards to methods (and visibility): since the row and column of a seat is a fairly open piece of information and will most likely not require anything more than a simple get/set of a variable, consider changing the accessibility of seatRow and seatCol to public. Commented Jan 17, 2013 at 20:23
  • That whole if/else if/else if/... mess can quite easily be replaced by seatArray[i][j].setCol('A' + j) (as long as j will never exceed 26, of course). Commented Jan 17, 2013 at 20:24
  • 1
    if(available) available = false; else available = true; is more simply written as available = !available; Commented Jan 17, 2013 at 20:24
  • 1
    @slyfox: I think you mean as long as j will never exceed 25. But the language doesn't guarantee that letters of the Latin alphabet are contiguous; they aren't in EBCDIC, for example. Commented Jan 17, 2013 at 20:28
  • @KeithThompson Yes, you're correct on both counts, thanks. In the absence of specific character set information I assumed ASCII/ISO-8859-1/UTF-8 (where this kind of character tomfoolery is valid) since that's what most people tend to work with nowadays. Commented Jan 17, 2013 at 20:34

2 Answers 2

1
seatPlan[i][j].setRow(row);

Here is the problem. seatPlan is not an array. It is the name of the function.

You meant seatArray. So it should be:

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

One suggestion: consider using std::array as:

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

instead of

Seat seatArray[4][6];
Sign up to request clarification or add additional context in comments.

Comments

1

void seatPlan() is a method and you're treating it as an array. Did you mean seatArray instead?

Also

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

? Really? Why not just

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

(assuming you fix the previous error)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.