I am using Xcode and it refuses to compile when passing reference to the string object itself.
(string &text, string remove)
without & it compiles. Is it my code that is wrong or could it be something with the project file?
this is the compiler error:
Undefined symbols for architecture i386:
"removeLetters3(std::string, std::string)", referenced from:
Main() in narcissism.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Code:
string removeLetters3(string &text, string remove)
{
for (int i = 0; i < remove.length(); i++)
{
int pos = 0;
while ((pos = text.find(remove[i], pos)) != string :: npos)
{
text.replace(pos, 1, "");
}
}
return "";
}
and here is how the function is called:
string text;
string rletter;
removeLetters3(text, rletter);
There is nothing wrong with your code but judging from your error I would assume that the declaration that the caller sees is this:
While your implementation reads
So when your linker tries to find the implementation of the first one it fails because there is no such implementation.
This is evidenced by the error:
notice the signature. It is not saying: