-2

I've just now come across an error using arrays that seems odd, I've searched the web but it would appear this is typically something people run into when they are dealing with multidimensional arrays. The error occurs when I attempt to call a function that uses an array as a parameter. Here is the code:

#include <iostream>
#include <string>
#include <iomanip>
#include "header.h"
#include <fstream>

using namespace std;

int main(){

   string make, model, licensePlate, address, name, phoneNumber;
   int year, messageCode;
   char choice;

   bool ready[10];
   string phoneNumber[10], name[10], address[10], licensePlate[10], make[10], model[10];
   int year[10];

   initializeArray(year[]);

The error occurs within the brackets of year[], expected an expression. Thanks in advance!

Dozar
  • 71
  • 2
  • 2
  • 6
  • 3
    That is not how you pass an array to a function. I suggest you avoid C-style arrays entirely and use `std::vector` – Neil Kirk Jan 19 '15 at 14:59
  • Could you provide the prototype of "initializeArray" function ? – CamiloR Jan 19 '15 at 14:59
  • 1
    First [learn some basic C++](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), then read about [`std::array`](http://en.cppreference.com/w/cpp/container/array). – Some programmer dude Jan 19 '15 at 15:00
  • You've defined `year` twice as a integer variable and an array of 10, which is wrong. When you want to pass an array, just passing the base address is good enough. – Sunil Bojanapally Jan 19 '15 at 15:02

1 Answers1

0

I apologize for my poor code!

Having both variables of int and an array with the same name was a terrible idea, as you do not use the brackets to pass an array. I removed the brackets and the int year variable.

Here is the revised work:

bool ready[10];
string phoneNumber[10], name[10], address[10], licensePlate[10], make[10], model[10];
int year[10];

initializeArray(year);
cadaniluk
  • 15,027
  • 2
  • 39
  • 67
Dozar
  • 71
  • 2
  • 2
  • 6