hey everyone, i have a problem compiling this program and i cant see what the problem is. basically i want to resize an array if it gets to its maximum size but it wont let me because of the error mentioned as the title :( can anyone help? here is the code, the error is in the resizeArray() function:
Person Person::resizeArray(Person passengers[], int size)
{
Person newPassengersData[passengers.size()*2] = new Person();
for (int k = 0; k < size; k++)
{
newPassengersData[k] = passengers[k];
}
delete passengers;
return newPassengersData;
}
int main()
{
string repeat;
string answer;
string name;
int i = 0;
int j;
int size = 1000;
Person passengerDatabase[size];
do
{
cout << "Enter the number to execute the following: \n"
<< "- Press 0 to add a Passenger\n"
<< "- Press 1 to see all Passengers\n"
<< "- Press 2 to delete most recent Passenger\n"
<< "- Press 3 to exit program\n\n"
<< "Number: ";
cin >> j;
switch (j)
{
case 0:
system("cls");
passengerDatabase[i].addPassenger(passenger);
passengerDatabase[i] = passenger;
if (i = size - 1)
{
passenger.resizeArray(passengerDatabase, i);
}
i++;
break;
case 1:
system("cls");
for (int j = 0; j < i; j++)
passengerDatabase[j].printPassenger(passengerDatabase[j]);
break;
case 2:
cout << "Are you sure you want to delete the last person added? (Y/n)";
cin >> answer;
if (answer.compare("N") != 0 || answer.compare("n") != 0)
{
passengerDatabase[i - 1].deletePassenger();
passengerDatabase[i - 2] = passenger;
i--;
cout <<"\nThe most recent person added has been deleted\n";
}
cout << endl;
break;
case 3:
exit(1);
break;
case 4:
system("cls");
cout << "Please Enter the passenger you wish to cancel: ";
cin >> name;
cout << endl;
//cancelPassenger(name, passengerDatabase);
break;
default:
cout << "Please enter an appropriate value!";
}
cout << "Would you like to repeat previous options? (Y/n)";
cin >> repeat;
if (repeat.compare("n") != 1 || repeat.compare("N") != 1)
{
exit(1);
}
cout << endl;
system("cls");
}
Hint: read up on vectors and get rid of arrays! The older and wiser programmers will scoff at this, but for newbies like us, vectors are a gift from heaven. They can do everything an array does and much more.