http://www.cplusplus.com/reference/algorithm/for_each/ Unary function taking an element in the range as argument. This can either be a pointer to a
The function object is taken by value. for_each returns the function object, so if you change it to:
for_each
multiply = std::for_each(vec.begin(),vec.end(),multiply);
you get the expected output.