range-loop-add-qasconst

This commit is contained in:
Andrei Astafev 2020-04-19 00:28:00 +03:00
parent b1652d77bf
commit 11f895bfff

View File

@ -3,6 +3,18 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
// function args by ref
int sum(QStringList sl)
{
int s = 0;
for(auto str: sl)
{
s += str.toInt();
}
return s;
}
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
QCoreApplication app( argc, argv ); QCoreApplication app( argc, argv );
@ -17,10 +29,20 @@ int main( int argc, char** argv )
// loop add ref // loop add ref
QStringList sl; QStringList sl;
for (auto s: sl) sl << "111" << "222" << "333";
for (const auto &s: sl)
{ {
qDebug() << s; qDebug() << s;
} }
// loop qasconst
for (auto s: sl)
{
s.append("0");
}
// function args by ref
auto ir = sum(sl);
return( 0 ); return( 0 );
} }