Consider such a class
template<int n, class T>
class dimArray {
T* arr;
int len[n];
public:
dimArray(int len₀, int len₁, int len₂, ..., int lenₕ₋₁, T initValue);
T& at(int x₀, int x₁, int x₂, ..., int xₕ₋₁);
void foo(int x₀, int x₁, int x₂, ..., int xₕ₋₁, .../*va_args*/);
}
used by
dimArray<2, double> a(3,4, 1.0);
a.at(1,2) = 4.3;
std::cout << a.at(2,3);
a.foo(1,2, 7.3,4.2,0);
The len₀
etc. are p code. Is it possible to make such thing in C++? If so, how?