 <p>Notes:</p> <ul> <li><p>I am assuming <code>Product::at(int)</code>is returning a <code>Transaction</code>, given a previous question.</p></li> <li><p>I am also assuming OP mean "built-in" when he or she wrote"static"</p></li> </ul> <p>The <code>for</code> can be removed using built-in functions. Some (many?) will find the new syntax less understandable, though.</p> <pre><code>QString Product::toString() { QStringList aggregate; std::transform(m_transactions.begin(), m_transactions.end(), std::back_inserter(aggregate), std::bind(std::mem_fn(&amp;Transactions::toString), std::placeholders::_1)); // or : [](const Transaction&amp; transaction){ return transaction.toString(); }); return aggregate.join("\n"); } </code></pre> <p><code>std::transform</code> will transform every <code>m_transactions</code> elements using <code>Transaction::toString()</code>, and place the results into <code>aggregate</code>. </p> <p><code>std::back_inserter</code> means "use <code>QStringList::push_bask</code> to record the results". If <code>QStringList</code> had a <code>resize(int)</code> like <code>QVector</code> does, we could have used <code>aggregate.begin()</code> instead.</p> <p>The unary function is a bit tricky, as it needs to be converted into a unary function, which what <code>std::bind</code>/<code>std::mem_fn</code> is doing. If you are using C++11, you can use a lambda instead.</p> <hr> <p>Also from the previous question, @SingerOfTheFall's remark is valid:</p> <blockquote> <p>I also find it a little odd to save transactions inside of products. A better design would be having a separate class that could store them.</p> </blockquote> <p>If you keep this design, <code>Transaction Product::at(int)</code> and <code>int Product::size()</code> should be renamed to make the link with <code>Transaction</code> explicit, like <code>getTransaction</code> and <code>getNumberOfTransactions</code>.</p>