当类型是类时,我需要一些关于向量向量的帮助。“loadTruck”是我的课。我想按以下顺序将我的类“loadTruck”中的值存储到二维向量中:向量(卡车,打印)。“卡车”和“打印”都是“loadTruck”类的类型。我想要访问这个向量:例如,让我们说“打印”是包装,“卡车”是卡车。我想获取有关卡车 1 中包裹的信息,包裹 ID 为 20。我对此感到非常困惑。
vector<vector <loadTruck>> jedinecTruck;
loadTruck truck;
while (warehouseIsEmpty == False)
{
truck.resetTruck();
for (int i = 0; i < numOfPackages; i++)
{
vector<loadTruck> print;
if (store2D[i].checkIfPackageIsThere() == true)
{
truck.setPackageSize(store2D[i].getPackageWidth(), store2D[i].getPackageHeight());
if (truck.checkIfPackageCanBeLoaded() == true)
{
print.push_back(truck);
truck.loadPackageInTruck();
store2D[i].deletePackage();
}
}
}
jedinecTruck.push_back(truck);
}
3D数组版本,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\这不是一个好主意,但我希望它能帮助你理解我想要做什么。我需要使用向量,因为我无法定义数组的前 2 个元素,它取决于算法并且总是在变化。对于这个例子,我假设前两个元素将被静态定义。第三个元素总是有 4 个组件。
vector<loadTruck> jedinecTruck;
loadTruck truck;
int array[1][3][4];
while (wharehouseIsEmpty == false)
{
truck.resetTruck();
for (int i = 0; i < numOfPackages; i++)
{
if (store2D[i].checkIfPackageIsThere() == true)
{
truck.setPackageSize(store2D[i].getPackageWidth(), store2D[i].getPackageHeight());
if (truck.checkIfPackageCanBeLoaded() == true)
{
truck.loadPackageInTruck();
store2D[i].deletePackage();
array[0][i][0] = truck.getActualX1();
array[0][i][1] = truck.getActualX2();
array[0][i][2] = truck.getActualY1();
array[0][i][3] = truck.getActualY2();
}
}
}
jedinecTruck.push_back(truck);
}
问候