I try to initialize structures of vectors that contains vector:
struct productionCanvas
{
int canvasID;
int indexXmlJob;
};
struct productionArea
{
int areaID;
std::vector<productionCanvas> canvasList;
};
The first level is correctly initialized but not the second one:
int areaIncr=0;
int canvasIncr=0;
std::vector<productionArea> production;
int addArea()
{
productionArea area{};
areaIncr++;
area.areaID = areaIncr;
area.canvasList = {};
production.push_back(area);
return areaIncr;
}
int addCanvas(int job)
{
productionCanvas canvas{};
canvasIncr++;
canvas.canvasID = canvasIncr;
canvas.indexXmlJob = job;
for (productionArea area : production)
{
if (area.areaID == areaIncr)
{
area.canvasList.push_back(canvas); // this line is triggered
break;
}
}
// Check if correctly push_back
for (productionArea area : production)
{
for (productionCanvas canvas : area.canvasList)
{
// This line is never triggered, why ?
}
}
return canvasIncr;
}
addArea(); // area correctly inserted
addCanvas(1); // canvas not inserted inside area
.
There is no return value of the push_back function, so I cannot know why it's not pushed back! It seemed that it does not work like Qt-QVector.
How to initialize these struct?