C
carl
In a function 'update()' I read and update a std::vector<MyObj> located in
another object 'Test'.
Now I would like these changes to be visible after 'update()' returns (both
for the container and the elements inside).
The function I use to read the std::vector<MyObj> therefore returns a
reference to the container:
std::vector<MyObj> & Test::getContainer()
{
return m_container;
}
Here is the implementation of 'update()'
void update(){
std::vector<MyObj> container = test.getContainer();
int size = container.size();
for (int i=0; i<size; i++) {
// Changes to objects in the container should be visible outside this
function.
MyObj & mo = container;
mo.setId(i);
}
// Below should be unnecessary
test->setContainer(container);
}
But the changes are not visible after 'update()' returns unless I add the
call:
test->setContainer(container);
after the above loop. But is the point of using references not that this
kind of explicit updating is unncessary?
another object 'Test'.
Now I would like these changes to be visible after 'update()' returns (both
for the container and the elements inside).
The function I use to read the std::vector<MyObj> therefore returns a
reference to the container:
std::vector<MyObj> & Test::getContainer()
{
return m_container;
}
Here is the implementation of 'update()'
void update(){
std::vector<MyObj> container = test.getContainer();
int size = container.size();
for (int i=0; i<size; i++) {
// Changes to objects in the container should be visible outside this
function.
MyObj & mo = container;
mo.setId(i);
}
// Below should be unnecessary
test->setContainer(container);
}
But the changes are not visible after 'update()' returns unless I add the
call:
test->setContainer(container);
after the above loop. But is the point of using references not that this
kind of explicit updating is unncessary?