This is a memory allocation issue that I\'ve never really understood.
void unleashMonkeyFish() { MonkeyFish * monkey_fish = new MonkeyFish(); std::string
If you use the following method declaration:
void setName( const std::string & parameter_name );
then you would also use the member declaration:
std::string name;
and the assignment in the setName
body:
name = parameter_name;
You cannot declare the name
member as a reference because you must initialise a reference member in the object constructor (which means you couldn't set it in setName
).
Finally, your std::string
implementation probably uses reference counted strings anyway, so no copy of the actual string data is being made in the assignment. If you're that concerned about performance, you had better be intimately familiar with the STL implementation you are using.