 <p>The other answers are technically correct on the compiler error, but miss a subtle point: <code>fun</code> is used incorrectly. It appears to be intended as a local variable that collects results in <code>fun.pairs</code>. However, <code>std::for_each</code> can copy <code>fun</code> instead, and then <code>fun.pairs</code> is not updated.</p> <p>Correct solution: <code>Fun fun = std::for_each(Packs, Packs + SHARE_PRIZE, Fun());</code>.</p>