Re: Return versus Side-Effect
On 30 Mar., 17:40, hdante <hda...@gmail.com> wrote:
On Mar 27, 10:08 am, jeungs...@gmail.com wrote:
I have a function that takes a single string in, does some
manipulation, then gives an output.
1.) I can write the function prototype like this:
void doManipulation( const std::string & input, std::string &
output ); // (uses side-effect to return ouput string)
(if you're not afraid of pointers) do this:
void doManipulation( const std::string & input, std::string *
output );
now the calls make the side-effect evident:
doManipulation(x, &y);
As I argued in another thread, the pointervalue is not evidence of
change.
More importantly: if there is doubt as to whether or not a function
changes its parameters, this is more an indication that the programmer
writing the call knows to little to call the function in the first
place.
/Peter
[snip]
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]