与a相同std::vector:
QVector< QVector< int > > twoDArray; // Empty.
QVector< QVector< int > > twoDArray( 2 ); // Contains two int arrays.
twoDArray[0].resize(4);
twoDArray[0][2] = 4; // Assign to the third element of the first array.
...
etc...
Run Code Online (Sandbox Code Playgroud)
为了避免嵌套向量,您可以将2D索引空间映射到1D索引空间,至少如果您有一些(常量)"宽度",它是x坐标的上限:
int index(int x, int y) {
return x + width * y;
}
Run Code Online (Sandbox Code Playgroud)
然后使用它来索引width * height大小的向量:
QVector<...> vector(width * height);
vector[index(5, 3)] = ...;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
22413 次 |
| 最近记录: |