/*getSize - which asks the user how many strings they want */
void getSize (int *numStrings)
{
cout << "How many strings would you like? " << endl;
cin >> *numStrings;
}
/*getSpace - which gets an array in the heap of the size requested by the user */
void getSpace (int numStrings, string newArray[] )
{
newArray = new string [numStrings];
}
/* inputData - which allows the user to input the strings and stores them */
void inputData (int *numStrings, string newArray[])
{
string data;
for (int i = 0; i < *numStrings; i++)
{
cout << "Please enter string #" << i << endl;
cin >> data;
newArray[i] = data;
cout << newArray[i] << endl;
}
}
I have a problem with my code and it says:
Undefined symbols for architecture x86_64:
"getSpace(int)", referenced from:
_main in main.o
The error message looks like it is from the linker (rather than compiler). If so, there are no syntax errors in the code.
The error message says that the main() calls a function that has name 'getSpace' and that takes one integer parameter.
The error message says that no object file included in linking contains implementation for such function.
The code, that you do show, does not contain implementation for such function. There is one 'getSpace', but that takes two parameters.
The compiler does not complain, because you do declare both versions of 'getSpace'.