It's definitely not possible to do what you want directly due to the type system's restrictions, but you may want to consider something like the following (in C++11 syntax):
#include <vector>
#include <array>
#include <iostream>
template <typename T, size_t x, size_t z>
struct Ragged : std::array<std::vector<std::array<T, z>>, x> {
Ragged(size_t y) {
for (auto &i : *this) {
i.resize(y);
}
}
};
int main() {
using R5y5 = Ragged<int, 5, 5>;
R5y5 a(3), b(4), c(2);
vector<R5y5> d{a, b, c};
d[1][1][2][3] = 99; // checked at() calls supported for all dimensions, too
for (auto const &d : D) {
for (auto const &x : d) {
std::cout << "[";
for (auto const &y : x) {
std::cout << "[";
for (auto const &z : y) {
std::cout << z << " ";
}
std::cout << "]";
}
std::cout << "]" << std::endl;
}
std::cout << std::endl;
}
}
This gets you multidimensional operator[] access to d and its elements, and allows you to put whatever y-dimensioned array inside d you want to. Note that the 3-dimensional pseudo-arrays are no longer stored completely compactly, but in potentially growable 2-D slices.
D?