jeudi 25 février 2021

deduced conflicting types for parameter '_BIter' ('int*' and 'int')

I was trying to implement a simple reverse array function:

void reverse(int (&arr)[], int n)
{
  int start = 0, end = n - 1;

  while (start <= end)
  {
    int temp = arr[start];
    arr[start] = arr[end];
    arr[end] = temp;
    start++;
    end--;
  }
}

In my main() I have this:

int brr[9]{10, 20, 30, 40, 50, 60, 70, 80, 90};
for (int i = 0; i < 9; i++)
{
  cout << brr[i] << " ";
}
cout << endl;

reverse(brr, 9);
for (int i = 0; i < 9; i++)
{
  cout << brr[i] << " ";
}

How ever I am not able to figure out why I am getting this error:

no matching function for call to 'reverse(int [9], int)'
65 |   reverse(brr, 9);

no known conversion for argument 1 from 'int [9]' to 'int (&)[]'
12 | void reverse(int (&arr)[], int n)

deduced conflicting types for parameter '_BIter' ('int*' and 'int')
65 |   reverse(brr, 9);

I want to know what is this behavior and how to correct it?

Thanks!

Aucun commentaire:

Enregistrer un commentaire