I'm trying to run a dynamic array that employs strings, but when I push it through a function I get compile errors 'dynamicArray': undeclared identifier
, 'string':undeclared identifier
, and illegal use of type 'void'
. All of these errors point to the header for some reason.
I call the pointer here:
string* dynamicArray = NULL;
I call the function here:
populateArray(dynamicArray);
What is in the header:
void populateArray(string *&dynamicArray);
The function:
void populateArray(string *&dynamicArray)
{
char decide;
bool moreStrings = true;
int counter = 0;
while (moreStrings == true)
{
counter ++;
dynamicArray = new string[counter];
cout << "\nEnter your string here:";
cin >> dynamicArray[counter - 1];
cout << "\nDo you want to enter another string? Y/N:";
cin >> decide;
decide = toupper(decide);
if (decide == 'N')
{
moreStrings = false;
}
}
}
PS: vector may be better, but I'm afraid that isn't an option. Please only offer fixes that deal with pointers.