Would be an c++ topic, which is the way to change variables values from references by a QString<List>?
-
Hi everybody i got have this piece of code. My main target is change the values of the variables to 0 but when it's iterating in foreach function doesn't changes their values. Example:
QList<int> integerList = {var1, var2, var3}; foreach(int x, integerList) x = 0;
And if build it as reference this sets me problems
QList<int> integerList = {var1, var2, var3}; foreach(int &x, integerList) x = 0;
-
Hi everybody i got have this piece of code. My main target is change the values of the variables to 0 but when it's iterating in foreach function doesn't changes their values. Example:
QList<int> integerList = {var1, var2, var3}; foreach(int x, integerList) x = 0;
And if build it as reference this sets me problems
QList<int> integerList = {var1, var2, var3}; foreach(int &x, integerList) x = 0;
-
Hi
try the c++ 11 range base loop instead of the foreach macro ?QList<int> integerList = {1, 2, 3}; for (int& x : integerList) { x = 0; }
however, you will only change the ints inside the list, not the original var1-var3
as they are just copied to the list. -
Hi
try the c++ 11 range base loop instead of the foreach macro ?QList<int> integerList = {1, 2, 3}; for (int& x : integerList) { x = 0; }
however, you will only change the ints inside the list, not the original var1-var3
as they are just copied to the list.@mrjj said in Would be an c++ topic, which is the way to change variables values from references by a QString<List>?:
however, you will only change the ints inside the list, not the original var1-var3
as they are just copied to the list.does the initializer list accept variables ?
-
@mrjj said in Would be an c++ topic, which is the way to change variables values from references by a QString<List>?:
however, you will only change the ints inside the list, not the original var1-var3
as they are just copied to the list.does the initializer list accept variables ?
@j-hilk
Well yes and no. :)
it will accept what class accepts but
by value will result in a copy.But you can do funky stuff if you like
int funky1=100; QList<int*> integerList = {&funky1}; *integerList[0] = 90; qDebug()<< funky1;
output: 90
however, im not sure its possible with no * or &.
then you need overloaded = i guess to keep tab on the actual variable. -
@j-hilk
Well yes and no. :)
it will accept what class accepts but
by value will result in a copy.But you can do funky stuff if you like
int funky1=100; QList<int*> integerList = {&funky1}; *integerList[0] = 90; qDebug()<< funky1;
output: 90
however, im not sure its possible with no * or &.
then you need overloaded = i guess to keep tab on the actual variable.