I am trying to erase a space in a string.
First Name is a private member variable so that is why I used an accessor function. Is something wrong with the following call? I keep on getting errors...
If getFirstName() returns a copy, you're only erasing it from the copy - you need to store the copy erase the space, and then setFirstName() to the modified string.
If getFirstName() returns a copy, you're only erasing it from the copy - you need to store the copy erase the space, and then setFirstName() to the modified string.
Well if the OP is calling the function correctly, getFirstName() would return a reference to itself and then call erase so I don't believe it is returning a copy.
But this is all speculation without actually seeing the class's code.
Well if the OP is calling the function correctly, getFirstName() would return a reference to itself and then call erase so I don't believe it is returning a copy.
You can always call non-const member functions on non-const rvalues. It is most likely that the OPer's getFirstName() returns a copy.
Ohh ok I see what you are saying now didn't really understand the OP at first sorry about that.
But we will still need a bit more information and the code to be able to tell you exactly what is going wrong. But LB is right you are most likely trying to alter a copy instead of the actual thing.