Why is foreach iterating with a const reference?

后端 未结 5 1521
生来不讨喜
生来不讨喜 2021-02-19 18:59

I try to do the following:

QList a;
foreach(QString& s, a)
{
    s += \"s\";
}

Which looks like it should be legitimate but

5条回答
  •  轮回少年
    2021-02-19 19:18

    Maybe for your case:

    namespace bl = boost::lambda;
    std::for_each(a.begin(),a.end(),bl::_1 += "s");
    

提交回复
热议问题