Why can't for_each modify its functor argument?

后端 未结 3 1830
猫巷女王i
猫巷女王i 2020-12-31 18:00

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

3条回答
  •  离开以前
    2020-12-31 18:16

    The function object is taken by value. for_each returns the function object, so if you change it to:

    multiply = std::for_each(vec.begin(),vec.end(),multiply);
    

    you get the expected output.

提交回复
热议问题