Completely new to pointers, so I apologize for the novice question. I am receiving a conversion error when trying to call my function. This function is supposed to return a pointer to an updated array that contains 1 at the end.
int* appendList(int x, int &arraySize, int *list)
{
arraySize++;
int *array2 = new int[arraySize];
for(int i=0; i < arraySize-1; i++)
{
array2[i] = list[i-1];
}
array2[arraySize]=x;
return array2;
}
My main function is as follows.
int main()
{
int size=0;
int *list;
cout << "Please enter the size of your array: ";
cin >> size;
list = new int[size];
cout << "\nPlease enter the numbers in your list seperated by spaces: ";
for(int i=0; i < size; i++)
{
cin >> list[i];
}
cout << endl;
cout << "The array you entered is listed below\n ";
for(int i=0; i < size; i++)
{
cout << setw(3) << list[i];
}
list = appendList(1, size, list);
for(int i=0; i < size; i++)
{
cout << setw(3) << list[i];
}
return 0;
}
The call to function appendList results in a conversion error for argument three, but I'm not sure why? The function parameters must stay the way they are.
Thank you for your help.
coutandsetwwithoutstd::, so I guess you declared ausing namespace stdabove. Then thelistvariable name may have collision withstd::list<T>. Try use other name.using namespace std;to expose all names from the std::.