如建议here我修复了我的二维数组数组,使它与Vector类一起工作。C++ - 基于矢量的二维物体阵列
头文件
#include <vector>
typedef std::vector<int> Array;
typedef std::vector<Array> TwoDArray;
这里是如何使用它:
TwoDArray Arr2D;
// Add rows
for (int i = 0; i < numRows; ++i) {
Arr2D.push_back(Array());
}
// Fill in test data
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
Arr2D[i].push_back(ofRandom(0, 10));
}
}
// Make sure the data is there
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
std::cout << Arr2D[i][j] << ' ';
}
std::cout << '\n';
}
我的问题是,我该怎么做同样的自定义对象,而不是INT号码?我已经尝试了通过MyObject更改int并使用push_back(new MyObject());但是当我尝试访问它的功能时它不能正常工作。
预先感谢您。
究竟出了什么问题? – 2010-07-30 11:43:44
尝试给出不起作用的代码片段和错误 - 也许我们可以看到一些东西。 – 2010-07-30 11:43:50