Код: Выделить всё
struct SomeStruct { QString first; QString second; QString third; ... };
void manipulateData(const QList& list, const SomeStruct& a, const SomeStruct& b, const SomeStruct& c)
{
}
Код: Выделить всё
list[0]->setValue(a.first);
list[0]->setData(b.first + c.first);
list[1]->setValue(a.second);
list[1]->setData(b.second + c.second);
... (maybe more for each)
Код: Выделить всё
void manipulateData(const QList& list, const SomeStruct& a, const SomeStruct& b, const SomeStruct& c)
{
struct TempStruct { SomeObject* obj; QString a; QString b; QString c; };
QList tempList = {
{list[0], a.first, b.first, c.first},
{list[1], a.second, b.second, c.second},
...
}
for(const auto& item: tempList)
{
item.obj->setValue(item.a);
item.obj->setData(item.b + item.c);
}
}
Проблема, с которой я все еще сталкиваюсь, заключается в том, что она все еще не ощущается как лучшая идея, так как мне приходится повторять слова «а.первый, б.первый, в.первый». Достаточно было бы заполнить его каким-то «способом» получения «первого», «второго», «третьего» в структуре «SomeStruct». Итак, в конечном итоге мне бы хотелось, чтобы моя структура выглядела (и была заполнена) примерно так:
Код: Выделить всё
void manipulateData(const QList& list, const SomeStruct& a, const SomeStruct& b, const SomeStruct& c)
{
struct TempStruct { SomeObject* obj; int getter}; //not sure about the type of getter
QList tempList = {
{list[0], &a.first - &a}, //diff in memory place?
{list[1], &a.second - &a},
...
}
for(const auto& item: tempList)
{
item.obj->setValue(*(&a+item.getter));
item.obj->setData(*(&b+item.getter) + *(&c+item.getter));
}
}
- Можно ли с уверенностью предположить, что &c + &(b.секунда)-&b=&(c.секунда) ?
Есть ли лучшее решение, может быть, более понятное?

Подробнее здесь: https://stackoverflow.com/questions/792 ... vertically