I just came up with a crazy idea to represent a 2D array using a tree or a map:

Qt Code:
  1. struct 2DArrayIndex { int x, y; ... };
  2. class 2DArray : public QHash<2DArrayIndex, int> {
  3. //...
  4. };
To copy to clipboard, switch view to plain text mode 

One would need a custom method to access the data, so that it returned some default value if the item under specified coordinates would not be present, but apart from that we'd have a nice representation of a sparse 2D array. It wouldn't make sense to do it this way with dense arrays though...