Why is foreach iterating with a const reference?

后端 未结 5 1218
生来不讨喜
生来不讨喜 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:30

    With C++11, Qt now encourages this standard for syntax instead of Qt foreach :

    QList a;
    for(auto& s : a)
    {
        s += "s";
    }
    

提交回复
热议问题